70分求助 #4前四个点wa了
查看原帖
70分求助 #4前四个点wa了
1153491
leisure_li楼主2024/10/18 21:50
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,op;
stack<int> L;
stack<int> R;
void op1(){
    int l,r;
    cin>>l>>r;
    L.push(l);
    R.push(r);
}
ll op2(ll k){
    ll ans=0;
    int i,j;
    while(k>0){
        i=L.top();
        j=R.top();
        if(k>=j-i+1){
            L.pop();
            R.pop();
            ans+=(j-i+1)*(i+j)/2;//等差数列求和
            k-=j-i+1;
        }
        else{
            R.pop();
            R.push(j-k);
            ans+=k*(j-k+1+j)/2;
            k=0;
        }
    }
    return ans;
}
int main(){
    cin>>n;
    while(n--){
        cin>>op;
        if(op==1) op1();
        else{
            ll k,ans=0;
            cin>>k;
            ans=op2(k);
            cout<<ans<<endl;
        }
    }
    return 0;
}
2024/10/18 21:50
加载中...