我用stl栈,把每个pop和top前面都加了
if(s.empty()==true)
return 0;
终于,当我在第33行添加时,RE全都变成了WA
#include<bits/stdc++.h>
#define hh printf("\n");
#define int long long
using namespace std;
int n;
stack<int> s1,s2;
signed main()
{
cin>>n;
while(n--)
{
int x;
cin>>x;
if(x==1)
{
int y,z;
cin>>y>>z;
s1.push(y);
s2.push(z);
}
else
{
int y,ans=0;
cin>>y;
int a=s1.top(),b=s2.top();
int c=b-a+1;
while(y>=c)
{
y-=c;
ans+=(a+b)*c/2;
s1.pop();
s2.pop();
if(s1.empty()==true)
return 0;
a=s1.top(),b=s2.top();
c=b-a+1;
}
s2.pop();
s2.push(b-y);
ans+=(b+b-y+1)*y/2;
cout<<ans<<endl;
}
}
return 0;
}