社区讨论
75pts求助
P7870「Wdoi-4」兔已着陆参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo2t79hb
- 此快照首次捕获于
- 2023/10/23 19:23 2 年前
- 此快照最后确认于
- 2023/10/23 19:23 2 年前
CPP
# include <iostream>
# include <cmath>
# include <cstring>
# include <string>
# include <algorithm>
# include <stack>
# include <queue>
# include <set>
# include <map>
using namespace std;
int t,x,l,r,sum,top=0;
long long k;
struct node {
int l,r;
}st[1000005];
int main(){
cin >>t;
while(t--){
cin >>x;
if(x==1) cin >>st[++top].l>>st[top].r;
if(x==2) {
cin >>k;
sum=0;
while(k>(st[top].r-st[top].l+1)){
k-=st[top].r-st[top].l+1;
sum+=(st[top].l+st[top].r)*(st[top].r-st[top].l+1)/2;
top--;
}
l=st[top].r-k+1;
sum+=(st[top].r+l)*(st[top].r-l+1)/2;
st[top].r=l-1;
cout <<sum<<endl;
}
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...