跳到正文

题解

题解 P6013 【压岁钱】

gyh20约 1 分钟
原文
文章信息与版本

文章信息

发布
2020年1月29日
收录
2026年6月14日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P6013

版本

  1. v1当前

第一题,签到题。

只要对3操作记录一个标记即可。

C++
#pragma GCC optimize(2,3,4,5)
#include<cstdio>
#define re register
using namespace std;
const int Mxdt=1000000;	
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}

inline int read()
{
	int res=0;char ch=gc();
	while(ch<'0')ch=gc();
	while(ch>='0')res=(res<<3)+(res<<1)+(ch^48),ch=gc();
	return res;
}
int n,opt,ans,x,y;
long long sum,a[1000002];
signed main(){
n=read();
for(re int i=1;i<=n;++i){
	opt=read();
	x=read();
	sum+=a[i];
	if(opt==1)sum+=x;
	else if(opt==2){
		if(sum>=x)sum-=x;
		else ++ans;
	}
	else{
		sum-=x;
		a[read()]+=x; 
	}
}
printf("%lld",ans); 
    return 0;
}
原文