求助P7870
  • 板块学术版
  • 楼主luo_xiaoran
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/7/3 13:02
  • 上次更新2023/11/3 11:47:48
查看原帖
求助P7870
605945
luo_xiaoran楼主2023/7/3 13:02

75分,讨论区还有很多人也卡在75,找出错误就是大功臣

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
stack<int> s;
int main(){
	scanf("%d",&n);
	while(n--){
		ll k,l;
		scanf("%d%lld",&k,&l);
		if(k-1){
			ll sum=0;
			while(1){
				int b=s.top();
				s.pop();
				int a=s.top();
				if(b-a+1<l){
					l-=(b-a+1);
					sum+=1ll*(a+b)*(b-a+1)/2;
					s.pop();
				}
				else{
					if(l==b-a+1){
						sum+=1ll*(a+b)*(b-a+1)/2;
						s.pop();
						break;
					}
					else{
						sum+=1ll*(b-l+1+b)*l/2;
						s.push(b-l);
						break;
					}
				}
			}
			printf("%lld\n",sum);
		}
		else{
			int r;
			scanf("%d",&r);
			s.push(l);
			s.push(r);
		}
	}
	return 0;
}
2023/7/3 13:02
加载中...