QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116669#6178. 区间子集问题serene_analysis100 ✓29ms128636kbC++172.3kb2023-06-29 18:53:392023-06-29 18:53:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-29 18:53:43]
  • 评测
  • 测评结果:100
  • 用时:29ms
  • 内存:128636kb
  • [2023-06-29 18:53:39]
  • 提交

answer

#include<algorithm>
#include<cstdio>
#include<vector>
const int maxn=2e3+5;
const int inf=1073741823;
int n;
int l[maxn],r[maxn];
std::vector<int>son[maxn];
int mx[maxn][maxn*2][2][2],mem[2][maxn*2][2][2],size[maxn];
void tomx(int &a,int b){
	a=(a<b?b:a);
	return;
}
void decide(int x){
	size[x]=1;
	for(int i=0;i<=maxn-2;i++)for(int p=0;p<=1;p++)for(int q=0;q<=1;q++)mx[x][i][p][q]=-inf;
	if(son[x].empty()){
		for(int p=0;p<=1;p++)for(int q=0;q<=1;q++)
			mx[x][0][p][q]=(1-q)*r[x]-(1-p)*l[x]/*,printf("mx[%d][0][%d][%d]=%d\n",x,p,q,mx[x][0][p][q])*/;
		return;
	}
	std::sort(son[x].begin(),son[x].end(),[](int now,int oth){return l[now]<l[oth];});
	mx[x][maxn-1][0][0]=-inf;
	for(int v:son[x])/*printf("x=%d,v=%d\n",x,v),*/decide(v);
	int now=0;
	for(int v:son[x]){
		now^=1;
		for(int j=0;j<=size[x]+size[v]+1;j++)for(int p=0;p<=1;p++)for(int q=0;q<=1;q++)mem[now][j][p][q]=-inf;
		if(mx[x][maxn-1][0][0]==-inf){
			mx[x][maxn-1][0][0]=114514;
			size[x]+=size[v];
			for(int j=0;j<=size[x];j++)for(int p=0;p<=1;p++)for(int q=0;q<=1;q++)
				mem[now][j][p][q]=mx[v][j][p][q]/*,printf("mem[%d][%d][%d][%d]=%d\n",now,j,p,q,mem[now][j][p][q])*/;
			continue;
		}
//		printf("decide:x=%d,v=%d\n",x,v);
		for(int i=0;i<=size[x];i++)for(int j=0;j<=size[v];j++)for(int p=0;p<=1;p++)
			for(int m=0;m<=1;m++)for(int q=0;q<=1;q++)tomx(mem[now][i+j+m][p][q],mem[1-now][i][p][m]+mx[v][j][m][q]);
		size[x]+=size[v];
	}
	for(int i=0;i<=size[x];i++){
		for(int p=0;p<=1;p++)for(int q=0;q<=1;q++){
			mx[x][i][p][q]=mem[now][i+1][p][q];
//			printf("mem[%d][%d][%d][%d]=%d\n",now,i+1,p,q,mem[now][i+1][p][q]);
			if(p)tomx(mx[x][i][0][q],mem[now][i][p][q]-l[x]);
			if(q)tomx(mx[x][i][p][0],mem[now][i][p][q]+r[x]);
			tomx(mx[x][i][p][q],mem[now][i][p][q]);
		}
//		for(int p=0;p<=1;p++)for(int q=0;q<=1;q++)printf("mx[%d][%d][%d][%d]=%d\n",x,i,p,q,mx[x][i][p][q]);
	}
	return;
}
int fa[maxn];
signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",l+i,r+i);
	l[0]=0,r[0]=inf;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)if(l[j]<l[i]&&r[i]<r[j]&&l[j]>l[fa[i]]&&r[j]<r[fa[i]])fa[i]=j;
		son[fa[i]].push_back(i);
	}
	int ans=0;
	for(int x:son[0])decide(x),ans+=mx[x][0][0][0];
	printf("%d",ans);
	return 0;
}
/*
4
1 10
2 3
5 9
6 7
*/
//namespace burningContract

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3552kb

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: 1ms
memory: 7452kb

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: 17716kb

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: 3ms
memory: 34200kb

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: 4ms
memory: 19924kb

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: 2ms
memory: 7360kb

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: 5712kb

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: 11ms
memory: 128624kb

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: 3ms
memory: 127448kb

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: 15ms
memory: 127364kb

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: 21ms
memory: 127732kb

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: 20ms
memory: 127672kb

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: 8ms
memory: 128324kb

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: 18ms
memory: 128636kb

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: 24ms
memory: 127736kb

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: 15ms
memory: 128396kb

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: 29ms
memory: 128468kb

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: 24ms
memory: 127668kb

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: 21ms
memory: 128500kb

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"