QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#192129#7523. Partially Free Mealucup-team918#AC ✓925ms203712kbC++202.7kb2023-09-30 13:39:472023-09-30 13:39:49

Judging History

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

  • [2023-09-30 13:39:49]
  • 评测
  • 测评结果:AC
  • 用时:925ms
  • 内存:203712kb
  • [2023-09-30 13:39:47]
  • 提交

answer

//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define N 200005
#define mod 998244353
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ld long double
#define SZ(x) (int)(x.size())
#define debug cout<<endl<<"ff"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define fi first
#define se second
#define INF 1e9
#define pq priority_queue
#define rep(x,a,b) for(int x=a;x<=b;x++)
int qpow(int a,int b){
	int res=1;
	for(;b;b>>=1){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}
/*int fac[N],ifac[N];
int C(int n,int m){
	if(m>n||m<0||n<0) return 0;
	return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
	ifac[N-1]=qpow(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}*/
/*struct node{
	int nxt,to;
}e[N<<1];
int cnt=1,head[N];
inline void add(int x,int y){
	e[++cnt].nxt=head[x];
	head[x]=cnt;
	e[cnt].to=y;
}*/
inline int lowbit(int x){return x&(-x);}
inline int read(){
  int x=0,t=1;char ch=getchar();
  while(ch<'0'||ch>'9'){
    if(ch=='-') t=-1;
    ch=getchar();
  }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch-'0');
        ch=getchar();
    }
    return x*t;
}
inline void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
int T,n,ans[N],num,rt[N];
#define ls(rt) tr[rt].ls
#define rs(rt) tr[rt].rs
#define sz(rt) tr[rt].sz
#define sum(rt) tr[rt].sum
pii a[N];
int cmp(pii a,pii b){return a.se<b.se;}
struct node{
	int ls,rs,sz,sum;
}tr[N*31];
void pushup(int rt){sum(rt)=sum(ls(rt))+sum(rs(rt));sz(rt)=sz(ls(rt))+sz(rs(rt));}
void update(int &rt,int p,int l,int r,int x){
	rt=++num;tr[rt]=tr[p];
	if(l==r){
		sz(rt)++;
		sum(rt)+=x;
		return;
	}int mid=(l+r)>>1;
	if(x<=mid) update(ls(rt),ls(p),l,mid,x);
	else update(rs(rt),rs(p),mid+1,r,x);
	pushup(rt);
}
int query(int rt,int l,int r,int res){
	if(l==r){return res*l;}
	int mid=(l+r)>>1,ans=0;
	if(sz(ls(rt))>=res) return query(ls(rt),l,mid,res);
	else return sum(ls(rt))+query(rs(rt),mid+1,r,res-sz(ls(rt)));
}
void solve(int l,int r,int x,int y){
	if(l>r) return;
	int mid=(l+r)>>1,mx=INF*INF,pos=0;
	for(int i=max(x,mid);i<=y;i++){
		int w=query(rt[i],1,INF,mid)+a[i].se;
		if(w<mx){
			mx=w;
			pos=i;
		}
	}
	ans[mid]=mx;
	solve(l,mid-1,x,pos);
	solve(mid+1,r,pos,y);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i].fi>>a[i].se;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) update(rt[i],rt[i-1],1,INF,a[i].fi);
	solve(1,n,1,n);
	for(int i=1;i<=n;i++) cout<<ans[i]<<'\n';
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5608kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 670ms
memory: 203644kb

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:

1318594
3208018
5570526
7340845
9223347
11149865
12332210
13476823
14788280
16172895
17768627
19336633
20693779
22005236
23389851
25073157
26760338
28509336
30294967
32093959
33976461
35893858
37754030
39588384
41470886
43388283
45309771
47309654
48837539
50417767
52079411
53762717
55190044
56577630...

result:

ok 200000 lines

Test #3:

score: 0
Accepted
time: 643ms
memory: 203560kb

input:

200000
847759212 808195187
499393947 158845704
286713001 829058634
347836790 268095042
525802369 342098012
260721485 611292083
95451146 853465743
666288241 921988396
958024432 522176958
284971271 952579505
408975858 657474613
444942472 596256250
291446883 538551864
942712385 142670067
239468458 9590...

output:

1398661
1990331
2912658
4186260
5510021
7421286
8925937
10233209
11427663
12466304
13739906
15048281
16438721
17917204
19556134
21034617
22945882
24964675
27046288
28988324
30624067
32102550
33629849
35258767
36683909
38129744
39608227
41135526
42764444
44559165
46466041
48377306
49860205
51250645
5...

result:

ok 200000 lines

Test #4:

score: 0
Accepted
time: 649ms
memory: 203620kb

input:

200000
453045091 809721921
853476741 595698118
218851090 887561745
864896419 760665890
291906050 833777661
706333418 479486544
207093005 36386646
969262171 137545723
501777026 470632513
238108337 821895650
757244578 277013047
715147479 651214680
995278884 359331973
20441197 903583173
61588145 378817...

output:

1629450
3451675
5862264
7342961
8475016
9707673
11350240
13021035
14824028
16466595
18145506
19755199
21397766
23219991
25058891
26869771
28383182
29992875
31635442
33457667
35296567
37269548
39205891
41028116
42867016
44839997
46268352
47600752
48988255
50421419
51854715
53368126
54897681
56507374
...

result:

ok 200000 lines

Test #5:

score: 0
Accepted
time: 513ms
memory: 203620kb

input:

200000
724371 812164590
786885 853213841
375367 446887348
442587 266053048
910413 644441954
304737 493015342
449866 304716006
711453 152694644
405700 232509173
921335 223801102
979624 725734275
524990 894904581
975621 908452940
211492 159635302
996047 882815311
201533 598711233
152477 256633677
9411...

output:

112065
210146
299616
337074
391448
445884
500608
562757
637222
714160
812241
882389
944538
1019003
1095941
1179290
1276070
1329394
1383830
1438554
1500703
1564162
1638627
1715565
1798914
1886244
1975154
2064372
2159112
2230385
2293760
2357219
2421075
2486440
2560905
2636978
2713916
2797265
2883902
2...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 460ms
memory: 203692kb

input:

200000
82260 816973645
63190 30304976
15365 98123005
79313 698909248
88351 460688945
45258 145977968
35624 362819795
34062 929296068
13142 373585892
93631 33870837
47414 576582646
25940 764754575
8424 255583152
73559 151261046
51329 935294030
89414 108264540
14984 966447646
70866 477634636
7290 9827...

output:

13886
30185
60597
84857
106218
121551
137850
159549
187975
207878
228613
247795
267766
282648
297981
314280
332886
353621
374388
396087
418706
437819
458554
479321
499571
520306
541073
562772
582630
603365
624132
645831
668408
688579
709314
730081
751780
774399
798048
821818
847209
872827
901523
930...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 325ms
memory: 203636kb

input:

200000
1286 819121925
8997 273901462
8502 181755051
7515 175443695
5821 856272297
7390 111029219
5073 269357259
1581 35806553
7694 913461554
8300 307364045
8256 33038036
5700 229695181
250 919848697
7280 624783228
434 719961279
1232 128882963
8258 924021143
3834 843971163
5625 811204037
1492 2383695...

output:

10995
13359
18477
23804
38945
55481
60947
66065
70271
75389
80027
84800
89342
93179
97100
101148
106126
111244
116478
121825
128995
137178
145792
155005
164337
174083
183478
191218
197417
203657
211242
219019
226857
233378
240963
248740
256578
264569
272752
280960
289628
298655
306432
314270
322261
...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 245ms
memory: 203632kb

input:

200000
567 821597362
373 531417185
779 814789710
275 754605445
952 666936589
710 124558017
702 537686619
862 50955474
368 675370982
298 782978552
302 481759264
979 473352314
43 395227840
286 954544414
336 150250305
150 259994546
687 928911202
544 406240134
464 667581860
838 887654894
448 771976144
6...

output:

2235
2529
8117
9377
11127
12070
13052
14782
17841
27938
30643
32380
33341
34322
35554
40606
41587
48349
49885
50880
55974
61036
62947
63942
65127
67401
71096
73392
83699
85485
91937
97919
99466
100691
109601
116546
117649
119086
120067
121062
123036
127602
135828
136809
137804
139170
140993
143831
1...

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 322ms
memory: 203584kb

input:

200000
342509701 342369477
832528915 833461380
305083321 305636073
97787821 97798679
401112695 400166019
206883814 207488357
445079803 443330686
821303339 823004195
951351563 950383862
236686106 237217287
770566641 771324127
877496005 877642151
663255937 664202372
135673848 136103612
150951930 15070...

output:

4774
13192
28262
41294
54737
69177
87401
108979
136735
171516
203369
235932
272900
312322
349380
390783
439807
483352
532557
582602
633629
687385
738524
790936
844462
900935
961981
1024307
1084112
1146567
1211897
1274425
1338357
1406537
1479843
1556923
1633866
1711704
1791657
1881450
1970659
2062277...

result:

ok 200000 lines

Test #10:

score: 0
Accepted
time: 925ms
memory: 203560kb

input:

200000
424022414 503814435
806902283 120847887
159591289 767965342
995943523 2143610
92544520 834485542
527264427 400514062
828167614 99803183
413473955 513851792
24326747 951399406
6268451 987557869
6272849 987547914
870148328 65988204
303041365 624808224
484331263 443537008
37039932 926091659
4153...

output:

925350356
999391812
999994451
1000006025
1000021200
1000037835
1000056852
1000076740
1000097083
1000120901
1000147884
1000181988
1000216572
1000251650
1000286776
1000323768
1000366528
1000422287
1000481162
1000540533
1000608040
1000675799
1000746490
1000821377
1000897452
1000976676
1001058192
100114...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 735ms
memory: 203652kb

input:

200000
9759806 12862172
8415499 95736535
1664414 820629803
7565617 186586129
261111 972339624
7956621 143743367
6294429 322756312
4413454 523200143
3368006 635522804
7403517 204183948
608424 934830718
4422409 522274240
1913974 793736435
8057121 133077799
5980092 355887936
3993010 567818961
4942527 4...

output:

10000783
20011188
30022081
40022551
50024199
60026734
70028178
80028243
90028965
100046652
110055224
120055198
130055194
140057106
150062462
160062436
170062432
180064899
190064522
200064261
210064094
220063840
230063579
240063412
250063301
260063275
270063271
280063802
290064997
300063037
310060827...

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 667ms
memory: 203712kb

input:

200000
496345 466577657
386215 586183375
35313 961776167
224787 757007012
129801 860004317
534510 426004787
538049 421998089
582677 373345535
638985 313251583
440542 527987482
314859 661869183
464254 501661850
381786 590849519
336796 638644881
436826 532036806
967339 17549076
948496 27686222
435981 ...

output:

1002712
2004799
3009688
4018445
5020295
6024231
7024510
8027273
9033770
10033936
11035128
12037972
13041280
14044477
15046153
16047926
17051947
18054285
19055635
20058952
21060245
22064572
23064761
24066353
25066487
26068892
27069602
28071028
29071938
30075808
31076639
32077776
33081667
34082393
350...

result:

ok 200000 lines

Test #13:

score: 0
Accepted
time: 500ms
memory: 203636kb

input:

200000
15216 836840562
70964 236430015
63200 319769248
72638 218445383
50711 453882897
7142 922491104
31371 662544679
60197 352769322
41403 554098222
76954 173314909
83661 102670370
92697 39042364
10030 892110253
39376 576601232
48265 480542224
74934 195010760
92547 39963180
7838 915208475
81256 128...

output:

104238
207651
309282
409662
510001
616589
720325
821076
925357
1030343
1131525
1232102
1332478
1433483
1538744
1642201
1747262
1847472
1947556
2047760
2154162
2255836
2355863
2457381
2557722
2657969
2757985
2861246
2968808
3073504
3180373
3284338
3388918
3489105
3589161
3692633
3794227
3904391
40047...

result:

ok 200000 lines

Test #14:

score: 0
Accepted
time: 336ms
memory: 203568kb

input:

200000
4678 497931091
2640 716453432
6128 342231079
8613 73961599
6966 252076583
3235 652413490
6687 281932985
5435 417357447
8145 123716301
1029 890108476
8087 130103799
9604 21356741
3855 586162704
3077 669287066
6905 258832414
8309 106104565
9921 4362813
4232 545009314
5371 423589629
3869 5846781...

output:

14579
25122
38514
54746
65555
76413
99719
113491
128752
140022
153279
167111
179004
192410
202723
215381
226126
236576
247249
257830
267919
280431
294595
304934
315546
328726
341429
358430
371825
382901
394180
405288
417371
431424
442612
453822
473579
493771
503880
521850
533608
544570
556337
568376...

result:

ok 200000 lines

Test #15:

score: 0
Accepted
time: 238ms
memory: 203560kb

input:

200000
27 972604774
156 832885943
161 827754255
877 67082798
943 31056414
243 740861264
60 937391032
229 756995050
222 763374572
716 231870198
445 522461729
509 452792900
588 369495498
661 290499149
818 122716973
63 933851278
128 863054306
528 431656637
270 710563993
979 12062387
276 703934949
483 4...

output:

6882
15009
18343
26780
28171
30634
48686
50820
57412
58718
60404
61525
68888
74001
75071
77154
78786
80464
88174
91233
94246
95615
97463
103806
106975
110006
113520
115308
123130
128798
137120
140594
142982
145385
146791
148761
155966
158695
162930
164268
165619
166792
170367
172525
176505
178059
18...

result:

ok 200000 lines

Test #16:

score: 0
Accepted
time: 222ms
memory: 203632kb

input:

200000
11 892126160
2 986862649
83 118159385
50 474606235
30 681179212
92 43004615
77 181587331
94 33800665
26 726163332
19 800955104
7 933100010
9 911106127
32 663731276
58 382884421
78 172731234
41 568328829
67 290835641
49 480293195
13 861453787
21 784813797
28 708545692
79 159193875
83 113012768...

output:

317
11873
13115
14025
14330
14983
19602
27044
28254
28746
32462
33642
38161
42404
44581
48582
49445
50652
55013
56448
61812
61939
62720
63555
64046
68780
72247
75938
77932
79081
81666
83359
85092
88610
92584
93935
101257
109306
111290
117823
119842
121331
123366
124841
124962
128531
135178
136626
13...

result:

ok 200000 lines