QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457334#8831. Chemistry Classucup-team3699#WA 155ms65912kbC++232.6kb2024-06-29 10:39:182024-06-29 10:39:19

Judging History

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

  • [2024-06-29 10:39:19]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:65912kb
  • [2024-06-29 10:39:18]
  • 提交

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 = 4e5+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);
        
        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: 9784kb

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: 0
Accepted
time: 155ms
memory: 65784kb

input:

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

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 138ms
memory: 65740kb

input:

1
199998 38987266278826 1
974183459404323858 517476981059568123 730207399881008603 532509909948600146 89227878552241675 16653300445469756 791674368913652595 92177901403222015 980536748304824579 581564387828767376 471919726893404451 759601909683722004 632340812998214017 818440789777778368 18845836031...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 149ms
memory: 65744kb

input:

1
199996 54170919220045 1
968843690955781467 596307347951820347 406785475849275444 383666938223357986 725160735782817082 132577412512120631 891899794864087098 779434145671998619 932681297277907326 208765550447928461 385078857912267975 669360937040314510 917331948890514855 505938744714587815 47145437...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 143ms
memory: 65604kb

input:

1
199998 35667463938291 8255384928693
770468016026697053 519790816750772730 110085058423772871 85144239858008037 782003096084947976 938498644167289660 693768718229582367 242186248813489674 155335549252315364 428982852761422230 890445026369869037 86401573937739054 9122788624365829 63351367715811463 1...

output:

193326

result:

ok 1 number(s): "193326"

Test #6:

score: 0
Accepted
time: 66ms
memory: 65560kb

input:

1
199998 30382921668955 14233448082254
963132297376532181 199422464083525159 322744997549904069 484222268324755182 911994852231141516 486452603601138945 442934186247306449 697067018736912231 391585717434570522 682442472054944522 79264788486972294 313368204441969076 399649435615099454 810055146752799...

output:

-1

result:

ok 1 number(s): "-1"

Test #7:

score: 0
Accepted
time: 140ms
memory: 65780kb

input:

1
200000 47927923462269 1
24665586551853470 302052529263706283 210309971053691602 263076256179345770 857799427692929388 314900213613059794 225906274300855842 877882541418616003 513956968201013413 567629150391542269 663560657201049943 575042209033964444 387676442637519091 186961317429366344 950630734...

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 146ms
memory: 65780kb

input:

1
199998 61818605050169 1
165409158781561806 460583142448212326 912671218554176848 626926695695102006 33152959806830617 136688663029016820 174877457605065935 419306800362435196 89763241467680808 834116262786866128 830483250820731866 942265949775152349 147293754228427769 117586183977037844 8168200855...

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 138ms
memory: 65568kb

input:

1
199996 34451027260033 1
601283108326080907 366774999584049325 421906214352697372 955853417529868631 15724846216041399 237313052425127959 21985568950819605 990795326302503510 838020773207917956 327286028784534617 668754577944547269 293491049615758976 560132287154617049 178505332245992034 5559649986...

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 60ms
memory: 65912kb

input:

1
200000 29187534610932 21950129578571
825099255469982093 186387713027671861 686187988858020000 84398649936510585 404799755268793918 343938261224617536 835021326555656778 414012550526058150 473262296466867769 949711165249895614 876342183912676727 446476677785448323 965973178373470399 211396195851941...

output:

-1

result:

ok 1 number(s): "-1"

Test #11:

score: 0
Accepted
time: 139ms
memory: 65836kb

input:

1
199997 29405605609626 28289738816956
142397526262523706 376764932667952907 458596335650559615 309998508007705361 216906502123233296 997270308488922036 627624046717378857 795390956936077907 455041452649155630 507550903995090795 945772023366794554 886164928026658833 740664590169344757 46022396065308...

output:

199994

result:

ok 1 number(s): "199994"

Test #12:

score: -100
Wrong Answer
time: 136ms
memory: 56708kb

input:

2
53064 111726463850469 1
699764699097067744 693901341124789557 936192127198912674 471397237345629646 57339338518673020 330275460175741176 277844690417194078 346832037195479397 384194477578957186 369530931475729901 783437009257722751 33766787198435970 978743274657154020 728022680382638786 5965748201...

output:

1446744073709551616
0

result:

wrong answer 1st numbers differ - expected: '0', found: '1446744073709551616'