跳到正文

个人记录

小信做核酸

jinruitao约 3 分钟
原文
文章信息与版本

文章信息

收录
2026年4月11日
更新
2026年7月3日
篇幅
约 3 分钟

版本

  1. v1当前

时间:2s 空间:256M

题目描述:

学校楼下在做核酸,为了证明有的同学今天做过核酸了,小信给做核酸的人都发了一张号码牌。小信会对同学们进行以下两种操作: 1 x y:让y个人加入排核酸的长队,并给他们每个人都发写着x的号码牌 。 2 y:从长队前面放行y个人去做核酸,并计算这y个人手里拿的号码牌的和。 请你帮助小信进行t次操作。

输入格式:

第一行包含一个整数 t。 随后t行每行按格式包含一次操作 。

输出格式:

对于每次2操作,输出一个整数表示答案。

样例1输入:

4 1 2 3 2 2 1 3 4 2 3

样例1输出:

4 8

样例2输入:

2 1 1000000000 1000000000 2 1000000000

样例2输出:

1000000000000000000

约定:

对于100%的数据,1≤t≤2×10^5,0≤x≤10^9,1≤y≤10^9。

思路:

油吸油吸,红场阅兵,又是你,现在我可会做了。

(⊙o⊙)…

5分,搞笑吧,多给点

C++
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,op;
queue<int>q;
int main() {
	cin>>t;
	while(t--){
		cin>>op;
		if(op==1){
			int x,y;
			cin>>x>>y;
			while(y--){
				q.push(x);
			}
		}
		else{
			int y,ans=0;
			cin>>y;
			for(int i=1;i<=y;i++){
				ans+=q.front();
				q.pop();
			}
			cout<<ans<<"\n";
		}
	}
	return 0;
}

要批量处理

标程

C++
#include<bits/stdc++.h>
using namespace std;
struct node{
	long long x;
	long long y;
}a[250000];
int head=1,tail;
long long sum=0;
int t;
int main() {
 scanf("%d",&t);
	while(t--){
		int op;
  		scanf("%d",&op);
		if(op==1){
   			tail++;
   			scanf("%lld%lld",&a[tail].x,&a[tail].y);
		}
		else{
			long long y;
  			scanf("%lld",&y);
    		while(y){
    			if(a[head].y<=y){
    				sum+=a[head].x*a[head].y;
    				y-=a[head].y;
    				head++;
				}
				else{
					sum+=a[head].x*y;
    				a[head].y-=y;
    				y=0;
				}
			}
			printf("%lld\n",sum);
			sum=0;
		}
	}
	return 0;
}

原文