50分求助
  • 板块P5587 打字练习
  • 楼主O_v_O
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/12/28 18:28
  • 上次更新2023/12/28 21:23:59
查看原帖
50分求助
852112
O_v_O楼主2023/12/28 18:28
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
	int x,y;
};
stack<node> s;
signed main(){
	int n;
	cin>>n;
	while(n--){
		int a,b,c;
		cin>>a;
		if(a==1){
			cin>>b>>c;
			s.push({b,c});
		}else{
			int ans=0;
			cin>>b;
			while(!s.empty()){
				node tmp=s.top();
				s.pop();
				int tmpx=tmp.x,tmpy=tmp.y;
				if(tmpy-tmpx+1>b){
					ans+=(tmpy-b+1+tmpy)*b/2;
					s.push({tmpx,tmpy-b});
					break;
				}else{
					ans+=(tmpx+tmpy)*(tmpx-tmpy+1)/2;
					b-=tmpy-tmpx+1;
				}
			}
			cout<<ans<<'\n';
		}
	}
	return 0;
}
2023/12/28 18:28
加载中...