RE求助
查看原帖
RE求助
526163
JwJ_2010楼主2021/10/10 18:35
#include<bits/stdc++.h>
using namespace std;
stack<pair<long long,long long> >st;
int main()
{
	//freopen("stack.in","r",stdin);
	//freopen("stack.out","w",stdout);
	int n;
	int op;
	long long l,r;
	long long k;
	cin>>n;
	for(int i=1;i<=n;i++)
	{   
		cin>>op;
		if(op==1)
		{
			cin>>l>>r;
			st.push(make_pair(l,r));
		}
		else
		{
			cin>>k;
			unsigned long long sum=0;
			pair<long long,long long>t=st.top();
			while((t.second-t.first+1)<=k)
			{
				sum+=(t.first+t.second)*(t.second-t.first+1)/2;
				st.pop();
				k-=(t.second-t.first+1);
				t=st.top(); 
			}
			if(k)
			{
				sum+=(t.second+t.second-k+1)*k/2;
				st.pop();
				st.push(make_pair(t.first,t.second-k));
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}
2021/10/10 18:35
加载中...