题目传送门
这道题 每次删除一个点 那么这个点必然在栈里面 那么如果堆顶不是他 我们就需要一次操作使得堆合理 这时我们可以把他删除然后把他下面的点打个标记表示这下面的点以后想怎么排就怎么排以后都不需要操作到 这样就解决问题啦 233
‘
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int M=3e5+7;int read(){int ans=0,f=1,c=getchar();while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}return ans*f;}int n,top,st[M],ans,cnt=1,f[M];int main(){char ch[15];int x;n=read();for(int i=1;i<=2*n;i++){scanf("%s",ch); if(ch[0]=='a') x=read(),st[++top]=x;else{if(!f[top]&&st[top]!=cnt) ans++,f[top]=1;if(f[top]) f[top]=0,f[top-1]=1;top--; cnt++;}}printf("%d\n",ans);return 0;}
View Code
如果觉得《codeforce C. Okabe and Boxes》对你有帮助,请点赞、收藏,并留下你的观点哦!