QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1164#725998#9601. I Wanna Makerchzhc_TheZoneFailed.2024-11-11 00:43:172024-11-11 00:43:18

Details

Extra Test:

Accepted
time: 0ms
memory: 3712kb

input:

1
3
1 2 6
2 7 11
2 1 5

output:

2

result:

ok single line: '2'

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725998#9601. I Wanna MakerTheZoneAC ✓54ms6756kbC++202.7kb2024-11-08 21:10:112024-11-08 21:10:11

answer

#include<bits/stdc++.h>
#define N 200010
#define ll long long
#define pll pair<ll,ll>
#define fi first 
#define se second
using namespace std;
int T,n;
ll k,x,lm,rm,l,r;
pll p[N];

void solve(){
    ll pl=0,pr=1e9;
    while(pl<pr){
        ll mid=(pl+pr+1)/2;
        if(k*(2*mid+k-1)/2>x) pr=mid-1;
        else pl=mid;
    }
    l=pl;
    pl=0;pr=1e9;
    while(pl<pr){
        ll mid=(pl+pr)/2;
        if(k*(2*mid-k+1)/2<x) pl=mid+1;
        else pr=mid;
    }
    r=pl;
    // cout<<l<<' '<<r<<" !!!\n";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        cin>>n;
        int cnt=0;
        lm=1e9;
        rm=0;
        for(int i=1;i<=n;i++){
            int t;
            cin>>t>>k>>x;
            solve();
            if(t==1){
                lm=min(l,lm);
                rm=max(r,rm);
                continue;
            }
            cnt++;
            p[cnt].fi=l;
            p[cnt].se=r;
        }
        if(!lm){
            cout<<"0\n";
            continue;
        }
        if(!cnt){
            cout<<"-1\n";
            continue;
        }
        cnt++;
        p[cnt].fi=lm;
        p[cnt].se=1e18;
        sort(p+1,p+cnt+1);
        ll ans=0,rx=1e18;
        // cout<<lm<<' '<<rm<<" !!\n";
        for(int i=cnt;i>=1;i--){
            rx=min(rx,p[i].se);
            // cout<<i<<' '<<p[i].fi<<' '<<p[i].se<<" !!\n"; 
            if(p[i].fi>lm) continue;
            if(p[i].fi>p[i-1].fi&&rx==1e18){
                ans=-1;
                break; 
            }
            ans+=(p[i].fi-p[i-1].fi)*max(0ll,rx-rm);
        }
        cout<<ans<<'\n';
    }
    return 0;
}
/*#include<bits/stdc++.h>
#define N 200010
#define ll long long
#define pll pair<ll,ll>
#define fi first 
#define se second
using namespace std;
int T,n;
ll k,x,lm,rm,l,r;
pll p[N];

void solve(){
    ll pl=0,pr=1e9;
    while(pl<pr){
        ll mid=(pl+pr+1)/2;
        if(k*(2*mid+k-1)/2>x) pr=mid-1;
        else pl=mid;
    }
    l=pl;
    pl=0;pr=1e9;
    while(pl<pr){
        ll mid=(pl+pr)/2;
        if(k*(2*mid-k+1)/2<x) pl=mid+1;
        else pr=mid;
    }
    r=pl;
    // cout<<l<<' '<<r<<" !!!\n";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        cin>>n;
        int cnt=0;
        lm=1e9;
        rm=0;
        for(int i=1;i<=n;i++){
            int t;
            cin>>t>>k>>x;
            solve();
            if(t==1){
                lm=min(l,lm);
                rm=max(r,rm);
                continue;
            }
            cnt++;
            p[cnt].fi=l;
        cout<<ans<<'\n';
    }
    return 0;
}*/