QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#626509#7622. Yet Another Coffeeucup-team4717#TL 796ms24084kbC++172.4kb2024-10-10 09:49:232024-10-10 09:49:23

Judging History

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

  • [2024-10-10 09:49:23]
  • 评测
  • 测评结果:TL
  • 用时:796ms
  • 内存:24084kb
  • [2024-10-10 09:49:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mid ((l+r)>>1)
#define ls son[x][0]
#define rs son[x][1]
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
const int N=2e5+5;
int n,m;
int a[N],b[N],id[N];
int root[N],tot;
int tree[N<<6],sum[N<<6],son[N<<6][2];
inline void update(int x){
	tree[x]=tree[ls]+tree[rs];
	sum[x]=sum[ls]+sum[rs];
	return;
}
void modify(int &x,int y,int l,int r,int w,int v){
	if(!x)x=++tot;
	if(l==r)return tree[x]+=1,sum[x]+=v,void();
	if(w<=mid)rs=son[y][1],modify(ls,son[y][0],l,mid,w,v);
	else ls=son[y][0],modify(rs,son[y][1],mid+1,r,w,v);
	update(x);
}
int query(int x,int l,int r,int L,int R){
	if(!x)return 0;
	if(L<=l&&r<=R)return tree[x];
	int cnt=0;
	if(L<=mid)cnt+=query(ls,l,mid,L,R);
	if(R>mid)cnt+=query(rs,mid+1,r,L,R);
	return cnt;
}
int ask(int x,int l,int r,int L,int R){
	if(!x)return 0;
	if(L<=l&&r<=R)return sum[x];
	int cnt=0;
	if(L<=mid)cnt+=ask(ls,l,mid,L,R);
	if(R>mid)cnt+=ask(rs,mid+1,r,L,R);
	return cnt;
}
int ask(int L,int R,int k){
	if(R-L+1<k)return 1e18;
	int l=0,r=n;
	while(l<r){
		if(query(root[mid],1,n,L,R)>=k)r=mid;
		else l=mid+1;
	}
	return ask(root[r],1,n,L,R);
}
void Init(){
	while(tot)tree[tot]=sum[tot]=son[tot][0]=son[tot][1]=0,tot--;
	n=read(),m=read();
	for(int i=1;i<=n;i++)b[i]=0;
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=m;i++){
		int r=read(),x=read();
		b[1]+=x,b[r+1]-=x;
	}
	for(int i=1;i<=n;i++)b[i]+=b[i-1];
	for(int i=1;i<=n;i++)id[i]=i;
	sort(id+1,id+n+1,[](int A,int B){return a[A]<a[B];});
	for(int i=1;i<=n;i++)root[i]=0;
	for(int i=1;i<=n;i++)
		modify(root[i],root[i-1],1,n,id[i],a[id[i]]);
}
int ans[N];
void sol(int l,int r,int L,int R){
	if(l>r)return;
	if(L==r){
		for(int i=l;i<=r;i++)
			ans[i]=a[L]-b[L]+ask(L+1,n,i-1);
		return;
	}
	int cnt=a[L]-b[L]+ask(L+1,n,mid-1),minn=L;
	for(int i=L+1;i<=R;i++){
		int res=a[i]-b[i]+ask(i+1,n,mid-1);
		if(res<cnt)cnt=res,minn=i;
	}
	ans[mid]=cnt;
	sol(l,mid-1,minn,R);
	sol(mid+1,r,L,minn);
}
signed main(){
	int T=read();
	while(T--){
		Init();
		sol(1,n,1,n);
		for(int i=1;i<=n;i++)printf("%lld ",ans[i]);printf("\n");
	}
	return 0;
}/*
2
5 2
1 2 3 4 5
3 1
4 2
7 3
4 3 1 10 3 8 6
4 9
3 8
4 5
*/ 

詳細信息

Test #1:

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

input:

5
10 14
17 37 59 65 53 73 68 177 160 111
10 177
5 193
2 30
3 63
2 339
3 263
5 178
2 190
9 23
10 328
10 200
9 8
3 391
6 230
12 9
152 306 86 88 324 59 18 14 42 260 304 55
3 50
2 170
1 252
7 811
1 713
7 215
10 201
4 926
8 319
19 20
182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...

output:

-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 
-3505 -3491 -3473 -3431 -3376 -3317 -3231 -3143 -2883 -2579 -2273 -1949 
-6527 -6496 -6448 -6374 -6258 -6092 -5922 -5743 -5563 -5368 -5167 -4934 -4691 -4428 -4156 -3875 -3591 -3272 -2946 
-3219 -2987 -2572 -2140 -1707 -1238 -768 -274 243 1...

result:

ok 70 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 12068kb

input:

2
5 2
1 2 3 4 5
3 1
4 2
7 3
4 3 1 10 3 8 6
4 9
3 8
4 5

output:

-2 0 3 7 12 
-21 -18 -15 -11 -5 3 13 

result:

ok 12 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 14004kb

input:

8
1 0
72916
9 11
130289 240521 653024 625847 679075 529899 486802 540872 353600
2 5400
2 257841
6 48161
3 71484
9 156788
3 181910
4 45589
6 210869
5 70426
9 87059
5 115764
8 7
634608 412120 360938 425426 825551 138578 678304 747502
2 235317
4 281859
5 553042
8 295615
8 32014
8 755313
4 439284
19 10
...

output:

72916 
-1121002 -880481 -526881 -40079 489820 1030692 1656539 2309563 2988638 
-2180324 -2041746 -1680808 -1255382 -620774 57530 805032 1630583 
-1025384 -1022941 -1018403 -1013731 -1006580 -998875 -987675 -970496 -953098 -932654 -909692 -886331 -862054 -835158 -807901 -779123 -747157 -713222 -67928...

result:

ok 85 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 11968kb

input:

5
18 24
561699155 345484852 420718917 108291879 553918474 392861085 299874093 28528146 248352314 398850144 248444258 89834833 251398697 101739017 240342391 320200928 481962939 343719433
5 354704
6 9355942
7 7098134
16 38746862
15 35848885
14 42058214
15 18411581
9 23207206
18 19518309
14 20707458
13...

output:

-416165974 -387637828 -297802995 -196063978 44278413 292630727 541074985 792473682 1079767658 1379641751 1699842679 2043562112 2436423197 2835273341 3255992258 3737955197 4291873671 4853572826 
335919368 705602908 
146524143 438492672 
-3870833640 -3817930784 -3749728771 -3627446160 -3471700060 -322...

result:

ok 39 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 12076kb

input:

9
30 20
150 250 278 8 74 295 357 116 543 287 37 345 14 173 153 407 136 269 121 109 318 401 280 500 267 257 238 312 225 477
10 293
13 162
29 145
13 120
2 17
3 192
21 70
7 102
1 286
18 50
1 296
3 308
21 24
13 118
8 22
9 52
21 156
11 258
9 263
23 234
13 20
145 133 51 146 103 103 44 154 173 68 171 13 6
...

output:

-3018 -3010 -2996 -2959 -2885 -2776 -2660 -2539 -2403 -2250 -2077 -1852 -1614 -1364 -1107 -840 -571 -293 -13 274 569 881 1199 1544 1901 2302 2709 3186 3686 4229 
-3232 -3226 -3213 -3169 -3118 -3050 -2947 -2844 -2699 -2553 -2399 -2228 -2055 
-23341 -23339 -23319 -23279 -23197 -23103 -22992 -22875 -22...

result:

ok 694 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 12116kb

input:

9
87 116
40104 112075 7416 91610 15866 12407 44611 15506 71100 14593 94026 42334 100025 20930 80680 11015 98242 109216 13019 67252 116919 68275 107504 52576 17004 40039 3037 3881 44570 1353 94585 79675 7339 45331 22404 97901 9724 80802 83388 2473 85549 94423 10967 43969 113695 20677 109374 20004 580...

output:

-38209921 -38209327 -38207974 -38205501 -38202766 -38199729 -38195848 -38188509 -38181002 -38171278 -38160931 -38149964 -38138949 -38126542 -38113990 -38100971 -38086378 -38071673 -38056167 -38040301 -38023297 -38005459 -37987197 -37967845 -37947841 -37927709 -37907032 -37886102 -37863698 -37839904 ...

result:

ok 983 numbers

Test #7:

score: 0
Accepted
time: 2ms
memory: 11972kb

input:

9
86 142
92213517 9496672 49452489 24822910 83754542 16205794 51389688 428375 1002851 48157164 52117680 59497763 17633347 58906367 68451067 79249434 54433105 31464502 7839830 61662667 51765587 76375691 4573781 56984987 44487325 2241633 52805129 47978257 15910569 100187672 23178562 42273363 79351960 ...

output:

-10124197529 -10124108337 -10123679962 -10122830890 -10121828039 -10120652318 -10118781420 -10116539787 -10113419124 -10108845343 -10102599494 -10095899018 -10088059188 -10076939018 -10063282872 -10049105892 -10033195323 -10016989529 -9999756298 -9982122951 -9963976050 -9945199830 -9923352279 -99010...

result:

ok 692 numbers

Test #8:

score: 0
Accepted
time: 20ms
memory: 12352kb

input:

6
1067 1710
10 126 165 174 30 63 80 3 27 92 236 228 111 23 149 204 136 88 112 209 215 97 174 33 191 119 132 119 75 148 217 100 44 228 219 242 192 135 199 192 116 60 101 183 201 7 110 98 29 160 46 17 202 62 140 33 155 7 95 4 64 31 203 171 126 160 153 245 230 53 172 200 63 46 238 145 224 72 40 89 13 9...

output:

-165754 -165753 -165752 -165751 -165750 -165749 -165748 -165746 -165744 -165742 -165740 -165737 -165734 -165731 -165727 -165723 -165719 -165715 -165711 -165707 -165702 -165697 -165692 -165687 -165682 -165677 -165672 -165666 -165660 -165654 -165648 -165642 -165636 -165630 -165624 -165618 -165611 -165...

result:

ok 7123 numbers

Test #9:

score: 0
Accepted
time: 33ms
memory: 14412kb

input:

10
91 60
121067 735043 657233 241687 762162 115139 571678 88967 287738 448211 122872 352608 564952 661168 284979 451332 533 423562 498017 727569 159355 138992 555614 14313 782085 93040 452229 478253 432717 529858 607759 84262 444015 85191 649296 465891 474353 301611 156490 683860 173773 337140 29060...

output:

-24499779 -24499246 -24492385 -24478072 -24437183 -24395244 -24339629 -24282938 -24216256 -24146644 -24062382 -23977191 -23891367 -23804635 -23715668 -23622628 -23507489 -23384617 -23255319 -23116327 -22959837 -22800482 -22628671 -22454898 -22269412 -22072264 -21830577 -21579729 -21323958 -21057640 ...

result:

ok 10787 numbers

Test #10:

score: 0
Accepted
time: 36ms
memory: 12384kb

input:

9
1216 716
157204975 195516644 282736891 144203909 389181163 124406996 48370860 15779707 258191873 424060854 216137375 362762758 255186885 62027462 127691552 307876772 32370909 165899011 265000287 213375339 305320675 12924365 193231703 244714450 149078313 174025044 73221562 224992083 206784534 11730...

output:

-24483429239 -24482693638 -24481572401 -24480434657 -24479296574 -24477908592 -24476425384 -24474880801 -24472417201 -24469943927 -24467377821 -24464568924 -24461519318 -24458455089 -24455196742 -24450363915 -24444363241 -24437812570 -24430644713 -24421737487 -24412522121 -24403223791 -24393082366 -...

result:

ok 10594 numbers

Test #11:

score: 0
Accepted
time: 796ms
memory: 24084kb

input:

8
11577 16477
228 100 299 369 11 376 87 141 179 287 609 128 172 354 85 423 115 246 312 439 258 203 583 127 8 435 631 557 202 247 228 308 376 490 640 15 213 76 163 634 50 2 408 467 571 157 213 261 164 118 523 532 528 586 396 307 259 372 39 372 322 301 445 206 60 77 351 347 150 193 257 626 111 418 546...

output:

-6288301 -6288300 -6288299 -6288298 -6288297 -6288296 -6288295 -6288294 -6288293 -6288292 -6288291 -6288290 -6288289 -6288288 -6288287 -6288286 -6288284 -6288282 -6288280 -6288278 -6288276 -6288274 -6288272 -6288270 -6288268 -6288266 -6288264 -6288262 -6288260 -6288258 -6288256 -6288253 -6288250 -62...

result:

ok 118048 numbers

Test #12:

score: 0
Accepted
time: 599ms
memory: 23120kb

input:

8
2170 1934
535263 726298 642479 218399 641782 854221 851733 174217 100075 706854 744111 40844 407229 735348 96977 431442 24001 835272 428435 286111 844410 397533 439877 445702 658631 150596 237445 323197 171130 177732 354629 618465 545837 260182 584719 108433 471186 423718 479470 890590 163725 6675...

output:

-172567265 -172566570 -172565524 -172564295 -172562209 -172559987 -172557543 -172554892 -172551242 -172547479 -172543694 -172539420 -172535093 -172530353 -172525450 -172520296 -172512330 -172504172 -172495755 -172487183 -172478602 -172469786 -172460922 -172452038 -172442964 -172433675 -172424140 -17...

result:

ok 89656 numbers

Test #13:

score: 0
Accepted
time: 589ms
memory: 23136kb

input:

9
17593 25702
383135191 2982885 579395998 27346375 549689611 171615873 459123924 590161106 513175283 299272610 386910229 335756449 493040798 472420555 114781943 260078547 592860852 609665441 142572193 570055541 168039635 211184400 495353178 420485670 419216517 193790110 460242138 308510752 271442416...

output:

-8758707761149 -8758707731246 -8758707672737 -8758707611486 -8758707514595 -8758707415987 -8758707300983 -8758707154905 -8758706987132 -8758706810997 -8758706454330 -8758706093315 -8758705701392 -8758705297835 -8758704870341 -8758704437699 -8758703987633 -8758703484731 -8758702944760 -8758702365444 ...

result:

ok 86646 numbers

Test #14:

score: -100
Time Limit Exceeded

input:

7
6800 5978
60 69 23 86 75 48 43 100 26 15 24 66 74 3 53 16 100 35 63 17 31 85 61 80 74 74 11 26 14 88 44 68 10 1 90 77 42 36 14 59 32 18 8 81 10 16 73 75 7 100 30 68 49 51 64 6 51 102 81 79 42 9 26 18 11 44 22 62 7 83 74 80 101 26 25 90 3 65 77 89 60 35 4 101 29 14 54 96 1 74 41 54 46 61 46 52 28 5...

output:

-1997112 -1997111 -1997110 -1997109 -1997108 -1997107 -1997106 -1997105 -1997104 -1997103 -1997102 -1997101 -1997100 -1997099 -1997098 -1997097 -1997096 -1997095 -1997094 -1997093 -1997092 -1997091 -1997090 -1997089 -1997088 -1997087 -1997086 -1997085 -1997084 -1997083 -1997082 -1997081 -1997080 -19...

result: