QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457330#8831. Chemistry Classucup-team3699#RE 0ms9768kbC++232.6kb2024-06-29 10:37:592024-06-29 10:38:00

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 10:38:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:9768kb
  • [2024-06-29 10:37:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define F first 
#define S second
#define pb push_back

const int mol=998244353;

const int N = 2e5+5;
struct Seg{
    int seg[N*4]={0},la[N*4]={0};

    void init(int n){
        for(int i=1;i<=n*4;i++) seg[i]=la[i]=-1e18;
    }
    void push(int ind){
        int t=la[ind];la[ind]=0;
        la[ind*2]+=t,la[ind*2+1]+=t,seg[ind*2]+=t,seg[ind*2+1]+=t;
    }
    void upd(int l,int r,int l1,int r1,int val,int ind){
        if(l1<=l&&r<=r1) {
            seg[ind]=val;
            la[ind]+=val;
            return;
        }
        int mid=l+r>>1;
        if(la[ind]) push(ind);
        if(r1<=mid) upd(l,mid,l1,r1,val,ind*2);
        else if(l1>mid) upd(mid+1,r,l1,r1,val,ind*2+1);
        else{
            upd(l,mid,l1,r1,val,ind*2);upd(mid+1,r,l1,r1,val,ind*2+1);
        }
        seg[ind]=max(seg[ind*2],seg[ind*2+1]);
    }

    int val(int l,int r,int l1,int r1,int ind){
        if(l1<=l&&r<=r1) return seg[ind];
        int mid=l+r>>1;
        if(la[ind]) push(ind);
        if(r1<=mid) return val(l,mid,l1,r1,ind*2);
        else if(l1>mid) return val(mid+1,r,l1,r1,ind*2+1);
        else return max(val(l,mid,l1,r1,ind*2),val(mid+1,r,l1,r1,ind*2+1));
        seg[ind]=max(seg[ind*2],seg[ind*2+1]);
    }
}iu1, iu2;
void solve(){
    int n, a, b;
    cin>>n>>a>>b;
    vector<int>aa(n*2+1), odd(n*2+1, 0), even(n*2+1, 0), dp(n*2+1, -1e18);
    
    for(int i=1;i<=n*2;i++) cin>>aa[i];
    sort(aa.begin()+1, aa.end());
    iu1.init(n*2);iu2.init(n*2);
    n*=2;
    for(int i=2;i<=n;i+=2){
        if(aa[i]-aa[i-1]>a){
            cout<<"-1\n";
            return;
        }
        even[i]=even[i-2]+(aa[i]-aa[i-1]<=b);
    }

    for(int i=3;i<=n;i+=2){
        odd[i]=odd[i-2]+(aa[i]-aa[i-1]<=b);
    }
    int t=1;dp[0]=0;
    for(int i=1;i<=n;i++){
        while(aa[i]-aa[t]>a) t++;
        if(i==1) {
            iu1.upd(1, n, i, i, 0, 1);
            dp[i]=-1e18;
            continue;
        }
        dp[i]=dp[i-2]+(aa[i]-aa[i-1]<=b);
        // cout<<i<<" "<<t<<" "<<odd[i-1]<<"\n";
        if(i%2){
            if(i-2>=t)
            dp[i]=max(dp[i], even[i-1]+iu2.val(1, n, t, i-2, 1));
            iu1.upd(1, n, i, i, -odd[i]+dp[i-1], 1);
        }
        else{
            if(i-2>=t)
            dp[i]=max(dp[i], odd[i-1]+iu1.val(1, n, t, i-2, 1));
            iu2.upd(1, n, i, i, -even[i]+dp[i-1], 1);
        }
    }
    cout<<dp[n]<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 9768kb

input:

4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
5 19 1
1 7 8 9 10 11 12 13 14 20

output:

-1
2
1
4

result:

ok 4 number(s): "-1 2 1 4"

Test #2:

score: -100
Runtime Error

input:

1
199996 67013419502794 1
403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...

output:


result: