QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325467#6178. 区间子集问题Lynkcat100 ✓47ms217264kbC++232.3kb2024-02-11 14:19:522024-02-11 14:19:52

Judging History

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

  • [2024-02-11 14:19:52]
  • 评测
  • 测评结果:100
  • 用时:47ms
  • 内存:217264kb
  • [2024-02-11 14:19:52]
  • 提交

answer

#include<bits/stdc++.h>
#define rfor(x...)for(register x)
#define rep(i,l,r)rfor(ll i=l;i<=r;i++)
#define per(i,l,r)rfor(ll i=l;i>=r;i--)
#define ref(i,l,r)rfor(ll i=l;i<r;i++)
#define IO(x...)freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define pow djsnfianj
typedef long long ll;typedef long double ld;const ll N=2e3+7,inf=1e18;typedef ll aN[N*2];aN head,tail,next,pre,up,to,l,r;
inline ll readll(){
    ll x=0,w=1;int c=getchar();for(;c<'0'||c>'9';c-'-'||(w=-w),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+(c^48),c=getchar());return x*w;
}int readchar(int l='0',int r='z'){if(l>r)std::swap(l,r);int c=getchar();for(;c<l||c>r;c=getchar());return c;}
ll cnt=0,top=0;void add(ll u,ll v){next[++cnt]=head[u],to[head[u]=cnt]=v;}int cmp(ll a,ll b){return r[a]>r[b];}
int qmax(ll&a,ll b){return a<b?a=b,1:0;}ll f[N][N][4],p1[N][N][4],p2[N][N][4],g[N][4];aN sl,sr,ansl,ansr,c,st;
void dfs0(ll u){
    ll x;f[u][0][0]=0,f[u][0][1]=l[u],f[u][0][2]=-l[u],f[u][0][3]=0,up[u]=0;
    rfor(ll i=head[u],v;v=to[i],i;i=next[i]){pre[next[i]]=tail[u]=i;
        dfs0(v),memcpy(g,f[u],sizeof(ll)*4*(up[u]+1)),memset(f[u],-0x3f,sizeof(ll)*4*(up[u]+up[v]+1+1));
        rep(j,0,up[u])rep(a,0,3)rep(k,0,up[v])rep(b,0,3)
        if(((x=a>>1)^(~b&1)||(i==head[u]&&!a))&&qmax(f[u][j+k+x][a^b^(x*3)],g[j][a]+f[v][k][b]))
        p1[v][j+k+x][a^b^(x*3)]=k<<4|a<<2|b;up[u]+=up[v]+1;
    }memcpy(g,f[u],sizeof(ll)*4*(up[u]+1)),memset(f[u],-0x3f,sizeof(ll)*4*(up[u]+1));
    rep(j,0,up[u])rep(a,0,3)rep(b,0,3)if(x=b&1,(a>>1^(~b&1)||(!b))&&j+x-1>=0)
    if(qmax(f[u][j+x-1][a^b^(x*3)],g[j][a]+((b&1)-(b>>1))*r[u]))p2[u][j+x-1][a^b^(x*3)]=a<<2|b;
}void dfs2(ll u,ll j,ll a,ll&nl,ll&nr){
    ll t=p2[u][j][a],x=0,y=0;j-=(t&1)+(t>>4)-1,a=t>>2&3;nl=t&1?r[u]:-1,nr=t&2?r[u]:-1;
    rfor(ll i=tail[u],v;v=to[i],i;i=pre[i])x=0,y=0,t=p1[v][j][a],dfs2(v,t>>4,t&3,x,y),
    t&2&&(~nl?sl[++top]=y,sr[top]=nl,nl=-1:(nr=y)),t&1&&(nl=x),j-=(t>>3&1)+(t>>4),a=t>>2&3;
    a&2&&(~nl?sl[++top]=l[u],sr[top]=nl,nl=-1:(nr=l[u])),a&1&&(nl=l[u]),ansl[u]=sl[top],ansr[u]=sr[top--];
}int main(){
    ll n=readll(),u,v;rep(i,1,n)l[c[i]=i]=readll(),r[i]=readll();std::sort(c+1,c+n+1,cmp);ll top=0,sum=0,x,y;l[0]=-1;
    rep(i,1,n+1){u=c[i];while(l[u]<l[st[top]])top--;!top&&(v=st[1])?dfs0(v),sum+=f[v][0][0],dfs2(v,0,0,x,y):
    add(st[top],c[i]),st[++top]=u;}printf("%lld\n",sum);
}
/*
3
0 10
2 5
6 7
*/

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 8000kb

input:

9
31 62
97 98
53 59
17 79
3 87
40 60
72 77
22 29
7 11

output:

69

result:

ok 1 number(s): "69"

Test #2:

score: 5
Accepted
time: 1ms
memory: 7912kb

input:

10
77 78
43 49
60 75
11 32
81 94
64 67
17 19
52 53
40 76
46 48

output:

57

result:

ok 1 number(s): "57"

Test #3:

score: 5
Accepted
time: 2ms
memory: 10612kb

input:

69
2356 2546
7498 7527
2114 2172
2866 4692
6101 6104
2607 2662
619 949
5495 5513
8013 8166
2704 2765
306 567
1192 1292
5241 6149
7468 7556
9455 9480
1926 1965
427 542
3033 3087
2218 2234
9423 9485
6312 6584
65 2857
1165 1341
4247 4615
7068 7241
8853 8971
9049 9061
7621 7747
6920 6925
2975 3405
8874 ...

output:

8167

result:

ok 1 number(s): "8167"

Test #4:

score: 5
Accepted
time: 0ms
memory: 14436kb

input:

226
907689292 910731765
637315418 640270766
649957861 656645930
330108609 332693231
327790388 341052210
452058987 452711364
164678004 227157125
701219833 702883478
35857149 36022443
652977298 655883456
200127263 204937919
873141333 894247545
964266670 986217229
168568045 174180280
743434879 76941787...

output:

848026569

result:

ok 1 number(s): "848026569"

Test #5:

score: 5
Accepted
time: 0ms
memory: 15768kb

input:

476
714654653 727563662
429167515 431143191
842243203 848961893
700045985 702768740
342430157 343401134
573738448 575113786
646109543 646481599
129101080 130854863
819944089 827765544
487460829 488975983
75470140 76077173
996513423 999545857
828006214 829269130
313030891 314257417
2556612 72746358
8...

output:

841569322

result:

ok 1 number(s): "841569322"

Test #6:

score: 5
Accepted
time: 0ms
memory: 14700kb

input:

244
195504221 200903817
183982018 184267455
886052909 887397280
774138753 778393959
885144456 885660700
773293500 780988242
480097924 558064110
207189240 208497911
802453825 812658707
706209219 722799069
688092845 691466627
285159759 290428263
482152317 482429364
359239303 365087642
982083965 983237...

output:

795087927

result:

ok 1 number(s): "795087927"

Test #7:

score: 5
Accepted
time: 1ms
memory: 12168kb

input:

61
4857 4890
2474 2581
7705 7729
2151 2212
3831 4045
675 680
6791 7772
132 1181
5859 6029
1861 1948
6183 6258
5673 5708
9728 9892
5025 5451
8361 8431
1200 2605
5033 5221
5016 5503
9102 9122
6453 6475
6286 6307
3645 3828
7285 7658
3198 3203
6692 8039
9948 9974
9136 9140
7866 7970
784 888
4761 4836
13...

output:

6957

result:

ok 1 number(s): "6957"

Test #8:

score: 5
Accepted
time: 1ms
memory: 10252kb

input:

48
4735 4834
5477 5835
3971 4180
907 1845
5552 5819
410 1872
9909 9983
1116 1449
6544 7083
1368 1433
5077 5143
122 8492
6059 6129
1481 1580
3423 3492
3918 4391
7724 7754
7174 7352
6735 6767
8592 9365
86 96
3356 3419
4441 4499
331 2433
926 1069
9453 9761
2004 2122
8523 9817
7902 8314
9834 9843
2860 3...

output:

7585

result:

ok 1 number(s): "7585"

Test #9:

score: 5
Accepted
time: 15ms
memory: 216976kb

input:

2000
999996000 999999999
999996001 999999998
999996002 999999997
999996003 999999996
999996004 999999995
999996005 999999994
999996006 999999993
999996007 999999992
999996008 999999991
999996009 999999990
999996010 999999989
999996011 999999988
999996012 999999987
999996013 999999986
999996014 99999...

output:

3998

result:

ok 1 number(s): "3998"

Test #10:

score: 5
Accepted
time: 0ms
memory: 27580kb

input:

2000
999996000 999996001
999996002 999996003
999996004 999996005
999996006 999996007
999996008 999996009
999996010 999996011
999996012 999996013
999996014 999996015
999996016 999996017
999996018 999996019
999996020 999996021
999996022 999996023
999996024 999996025
999996026 999996027
999996028 99999...

output:

2000

result:

ok 1 number(s): "2000"

Test #11:

score: 5
Accepted
time: 7ms
memory: 45808kb

input:

2000
186292029 186381429
39531755 39997885
715829714 715943849
89593082 89975740
501618789 502142452
524895573 525177152
239867002 239989666
90634704 90840196
347118449 347622111
937915910 938117133
37592276 37754952
148576316 148874708
9347683 9627715
946069019 946148305
192522660 192836061
1006072...

output:

518221954

result:

ok 1 number(s): "518221954"

Test #12:

score: 5
Accepted
time: 31ms
memory: 217264kb

input:

2000
26277805 971703271
441822414 547285226
22630689 976323424
177503973 838783634
359289289 622892772
336566267 653471488
468554386 471234224
211952703 802002437
275616745 718960728
488074800 488251685
270761751 724659408
98076671 917014793
188142828 828559658
33718424 968949516
414639447 570469725...

output:

999481159

result:

ok 1 number(s): "999481159"

Test #13:

score: 5
Accepted
time: 24ms
memory: 174460kb

input:

2000
106612522 904126667
454199953 459183353
518266011 521309001
100152739 912058268
118630668 891166021
73939844 935218444
184402560 818639601
275980248 281176406
640956183 643120656
576495602 577327144
302302907 306330636
46420140 957275508
86493782 923649549
190816371 816086677
59971696 946574467...

output:

999768008

result:

ok 1 number(s): "999768008"

Test #14:

score: 5
Accepted
time: 3ms
memory: 35500kb

input:

2000
834317527 837483207
871389010 877611186
251418042 251768616
692807140 695715240
980698227 980757849
860246405 869437586
315175804 318104161
297132323 297762460
697999996 698512693
921473187 943059724
172530643 173152426
29249487 29496853
668322217 668577462
409724653 410213113
662520150 6631430...

output:

834266055

result:

ok 1 number(s): "834266055"

Test #15:

score: 5
Accepted
time: 36ms
memory: 175264kb

input:

2000
22260436 983513300
44838411 959813215
178325390 819236924
191801218 805837790
686893042 687006983
366369393 366889609
588266579 629664794
717449062 718633671
448280421 449080467
434924925 446983549
488707390 489188828
242289139 746330221
47463138 957512142
7739035 994947857
489705763 492780357
...

output:

998764362

result:

ok 1 number(s): "998764362"

Test #16:

score: 5
Accepted
time: 47ms
memory: 192244kb

input:

2000
93109583 914905690
321520881 324064593
293243664 715774698
82783636 927527844
265688192 739625011
32757327 974206351
237459822 769556241
655287073 655726696
202305001 801303875
383923155 383928230
259669745 745121842
107036497 902898650
302132562 704877392
151976811 853539335
626692562 62765552...

output:

999353069

result:

ok 1 number(s): "999353069"

Test #17:

score: 5
Accepted
time: 0ms
memory: 35696kb

input:

2000
490101141 491331623
493416297 493544197
250031938 255484592
169345113 170934038
358634879 359110770
275923033 276381509
816955174 817466221
868403211 868930384
429367760 429946920
966828782 966998727
275548906 279511969
718471635 718949435
823236205 823940122
475357447 476832667
106562982 10828...

output:

771318558

result:

ok 1 number(s): "771318558"

Test #18:

score: 5
Accepted
time: 27ms
memory: 181436kb

input:

2000
400419022 400515434
311805468 312563722
513848101 514429488
557006776 557077877
53675155 954215429
70688309 933142221
116626359 884974190
728863542 728996879
462652370 463341088
57964317 948157377
279739587 279927638
70204877 935018658
564513118 564686325
182175743 813676272
70731735 932948734
...

output:

999760084

result:

ok 1 number(s): "999760084"

Test #19:

score: 5
Accepted
time: 19ms
memory: 183244kb

input:

2000
409036366 416844473
618790087 619213533
7403331 994487672
163952573 829019701
215041441 781602949
217762165 779732629
43881986 953602305
684439518 687102112
240342797 761725553
78486686 918019439
200034282 795877377
253486418 743160520
673597366 673693533
272648301 723654511
55221277 944002628
...

output:

999494881

result:

ok 1 number(s): "999494881"

Test #20:

score: 5
Accepted
time: 38ms
memory: 177608kb

input:

2000
301098910 301463273
172899058 822678193
303061223 304250391
455852994 457327795
342099842 351024966
353859985 360223624
80309261 916568803
100842570 899492109
62985101 937484158
183972063 807953314
665766799 665922782
379373982 379758598
145991794 855328796
653383586 691457465
436578769 4385278...

output:

998998410

result:

ok 1 number(s): "998998410"