QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269682#6156. 冰火战士osky123456100 ✓1371ms55884kbC++142.3kb2023-11-29 21:22:462023-11-29 21:22:48

Judging History

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

  • [2023-11-29 21:22:48]
  • 评测
  • 测评结果:100
  • 用时:1371ms
  • 内存:55884kb
  • [2023-11-29 21:22:46]
  • 提交

answer

// Problem: P6619 [省选联考 2020 A/B 卷] 冰火战士
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P6619
// Memory Limit: 512 MB
// Time Limit: 3000 ms
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
const int maxn = 2e6+100;
int n,ans[maxn][2],node[maxn],cnt,sum ;
struct element{
	int opt,t,x,y;
}q[maxn] ;
#define lowbit(x) x&(-x) 
void add(int x,int val ,int tag) {
	while(x <= cnt) {
		ans[x][tag] += val ;
		x += lowbit(x) ;
	}
}
int query(int x,int tag) {
	int res = 0; 
	while(x) {
		res += ans[x][tag] ;
		x -= lowbit(x) ;
	}
	return res ;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n ; 
	for(int i=1;i<=n;++i) {
		cin >> q[i].opt >> q[i].t ;
		if(q[i].opt == 1) {
			cin >> q[i].x >> q[i].y ;
			node[++cnt] = q[i].x ;
		}
	}
	sort(node+1,node+1+cnt) ;
	cnt = unique(node+1,node+1+cnt)-node - 1 ;
	for(int i=1;i<=n;++i) {
		if(q[i].opt == 1 ) {
			q[i].x = lower_bound(node+1,node+1+cnt,q[i].x) - node;
			if(!q[i].t) add(q[i].x,q[i].y,0) ;
			else {
				sum += q[i].y ;
				add(q[i].x+1,q[i].y,1) ;
			} 
		}
		else {
			if(!q[q[i].t].t) add(q[q[i].t].x,-q[q[i].t].y,0) ;
			else {
				sum -= q[q[i].t].y ;
				add(q[q[i].t].x+1,-q[q[i].t].y,1) ;
			}
		}
		int pos=0,ans1=0,ans2=0,temp1=0,temp2=sum ;
		for(int j = 20 ; ~j ; --j) {
			if((pos|(1<<j)) > cnt ) continue;
			int p = pos | (1<<j) ;
			temp1 += ans[p][0] ;
			temp2 -= ans[p][1] ; 
			if(temp1 >= temp2) {
				temp1 -= ans[p][0] ;
				temp2 += ans[p][1] ;
				continue;
			}
			ans1 = temp1 ;
			pos = p ;
		}
		if(ans1 && pos == cnt) {
			cout << node[pos] << ' ' << (ans1<<1) << '\n' ;
			continue;
		}
		ans2 = sum - query(pos+1,1 );
		if((!ans1 && !ans2) || query(pos+1,0) < ans2) {
			cout << "Peace\n" ;
			continue;
		}
		if(ans1 > ans2) {
			cout << node[pos] << ' ' << (ans1<<1) << '\n' ;
			continue;
		}
		temp1 = 0 , temp2 = sum , pos = 0 ;
		for(int j=20;~j;--j) {
			if((pos | (1<<j)) > cnt ) continue;
			int p = pos|(1<<j) ;
			temp1 += ans[p][0] ;
			temp2 -= ans[p][1] ;
			if(temp1 < temp2 || temp2 == ans2 ) {
				pos = p ;
				continue;
			}
			temp1 -= ans[p][0] ;
			temp2 += ans[p][1] ;
		}
		cout << node[pos] << ' ' << (ans2<<1) << '\n' ;
	}
	return 0;
}


详细

Test #1:

score: 10
Accepted
time: 1ms
memory: 5464kb

input:

100
1 0 218 8134
2 1
1 0 322 4393
1 1 582 4233
1 0 426 4960
1 0 563 3003
1 1 71 7234
1 1 979 934
1 1 691 7228
1 1 723 1288
1 0 243 717
1 1 440 1860
1 1 128 76
1 0 230 4481
1 0 608 5824
2 3
1 0 107 6946
1 1 948 1161
1 1 108 5000
1 0 155 5615
2 15
1 1 927 6672
1 0 812 3669
1 1 95 7297
1 1 28 1482
2 6
...

output:

Peace
Peace
Peace
582 8466
582 8466
582 8466
582 8466
582 10334
582 24712
582 24712
582 26146
582 26146
582 26146
440 29102
440 29102
582 26322
440 31086
440 33408
440 33408
440 33408
440 33408
440 45438
440 45438
440 45438
440 45438
440 45438
440 45438
440 46752
440 46752
440 46752
440 46752
440 46...

result:

ok 100 lines

Test #2:

score: 10
Accepted
time: 2ms
memory: 5640kb

input:

10000
1 1 617 3010
1 1 618 1611
1 1 618 8241
1 1 619 2442
1 1 620 7838
1 0 620 213
1 0 620 9615
1 1 620 5337
1 0 621 1309
1 0 622 1864
1 1 622 5158
1 1 622 348
1 0 622 3882
1 1 622 824
1 0 622 5246
1 1 622 761
1 1 623 2455
1 1 624 4419
1 1 624 8757
1 1 624 2328
1 1 625 9786
1 1 626 6994
1 1 626 2378...

output:

Peace
Peace
Peace
Peace
Peace
620 426
620 15676
620 19656
620 19656
620 19656
620 19656
620 19656
620 19656
620 19656
620 19656
620 19656
620 19656
622 27930
622 44258
622 44258
624 44258
624 44258
624 44258
624 44258
625 44258
626 45794
626 45794
626 45794
626 45794
628 45794
628 45794
628 45794
62...

result:

ok 10000 lines

Test #3:

score: 10
Accepted
time: 6ms
memory: 5608kb

input:

10000
1 1 867 9673
1 0 868 374
1 0 868 8754
1 0 868 5112
1 1 868 866
1 0 869 5341
1 0 870 6811
1 1 870 3136
1 1 870 1543
1 1 871 6525
1 1 871 1674
1 1 872 1838
1 1 873 7148
1 1 873 3262
1 1 873 1301
1 0 873 7434
1 1 874 5359
1 0 874 2808
1 0 874 2510
1 0 874 2152
1 1 875 5263
1 1 876 7616
1 0 876 85...

output:

Peace
Peace
Peace
Peace
868 1732
868 1732
868 1732
868 8004
868 11090
868 24140
868 27488
870 29432
870 43728
870 50252
870 52784
870 52784
871 52784
871 52784
871 52784
871 52784
871 52784
873 59898
873 59898
873 64396
873 67652
873 67652
873 67652
874 82592
875 82592
876 99688
876 99688
876 99688
...

result:

ok 10000 lines

Test #4:

score: 10
Accepted
time: 94ms
memory: 12732kb

input:

200000
1 0 68501 4107
1 0 114713 4264
1 0 79273 9390
1 0 59365 5025
1 1 154543 9706
1 1 195251 2745
1 1 105643 632
1 0 23703 8863
1 0 95321 2975
1 1 197593 2537
1 0 198906 3676
1 1 187265 2227
1 1 94557 9531
1 1 30342 3049
1 0 138225 2469
1 1 196601 8832
1 0 120056 743
1 0 10889 4446
1 0 3473 455
1 ...

output:

Peace
Peace
Peace
Peace
154543 19412
154543 24902
105643 26166
105643 26166
105643 26166
105643 31240
105643 31240
105643 35694
94557 54756
94557 54756
94557 54756
94557 54770
94557 54770
94557 63662
94557 64572
94557 72420
94557 72420
94557 89468
94557 89468
81597 102226
81597 102226
81597 102226
8...

result:

ok 200000 lines

Test #5:

score: 10
Accepted
time: 104ms
memory: 11108kb

input:

200000
1 0 183981 1897
1 0 75105 2383
2 1
1 1 122913 2305
2 4
1 0 166063 5502
1 0 104001 4089
1 1 14 6405
1 0 115017 891
1 0 45734 9976
2 7
1 0 82385 570
1 1 33811 2907
1 0 118337 3336
1 0 80880 3103
1 0 49711 9838
1 0 70429 4710
1 1 95279 1936
1 0 135871 1761
1 0 187701 580
1 1 77073 5299
1 1 14062...

output:

Peace
Peace
Peace
122913 4610
Peace
Peace
Peace
Peace
Peace
Peace
Peace
Peace
Peace
Peace
Peace
Peace
Peace
95279 3872
95279 3872
95279 3872
77073 14470
77073 17256
77073 17256
77073 17256
77073 17256
77073 17256
77073 17256
77073 17256
77073 17256
54047 19952
54047 19952
54047 19952
58917 19952
540...

result:

ok 200000 lines

Test #6:

score: 10
Accepted
time: 93ms
memory: 11088kb

input:

200000
1 0 100908 5091
1 1 50240 5983
1 0 198465 1950
1 1 147925 610
1 1 107569 9345
1 0 126728 6141
1 1 157465 2742
1 0 14879 3002
2 1
1 0 174194 5987
1 0 156741 2887
1 1 159685 3784
1 0 172136 4317
1 0 170361 871
1 1 117603 1002
1 0 142251 1949
1 1 187581 9460
1 1 100500 523
1 0 167172 7820
1 0 71...

output:

Peace
Peace
Peace
147925 1220
107569 10182
107569 10182
107569 10182
107569 16186
147925 6704
147925 6704
147925 6704
147925 14272
147925 14272
147925 14272
147925 14272
147925 14272
157465 27958
157465 27958
157465 27958
157465 29166
157465 31972
157465 31972
157465 34430
157465 34430
157465 34430
...

result:

ok 200000 lines

Test #7:

score: 10
Accepted
time: 1244ms
memory: 51668kb

input:

2000000
1 0 1217091 107
1 0 1765937 30
2 1
2 2
1 0 758967 946
1 1 1726929 789
1 0 1866918 861
1 0 841825 869
1 0 1734601 47
1 1 877281 397
1 0 1619742 549
2 5
1 1 590165 542
1 0 332203 963
2 8
1 1 1526271 702
1 0 914523 449
1 0 1711581 229
1 1 1939244 63
1 1 645419 616
1 1 1526125 930
1 0 639503 193...

output:

Peace
Peace
Peace
Peace
Peace
1726929 1578
1726929 1578
1726929 1578
1726929 1578
877281 2372
877281 2372
877281 1738
877281 1738
877281 2372
877281 1926
1526271 1926
1526271 2824
1526271 2824
1526271 2824
1526271 2824
1526271 2824
1526125 3210
1526125 4968
1190423 5100
1190423 5100
1190423 5100
119...

result:

ok 2000000 lines

Test #8:

score: 10
Accepted
time: 1292ms
memory: 50892kb

input:

2000000
1 0 1846771 368
1 1 1884221 616
1 0 1582901 883
1 1 890448 498
1 0 1169093 113
1 1 858334 764
1 0 317696 641
1 0 1152391 874
1 1 1548506 552
1 0 1716021 263
1 1 1206791 754
1 1 101157 555
1 1 1229682 332
1 1 5411 776
1 0 560553 469
1 0 503881 718
1 1 1454571 850
2 4
1 1 1255962 189
1 1 46296...

output:

Peace
1884221 736
1884221 1232
1884221 1232
1884221 1232
1884221 1232
890448 1282
890448 1282
1548506 2336
1548506 2336
1206791 3256
1206791 3256
1206791 3256
1206791 3256
1206791 4194
1206791 4508
1206791 5630
1206791 5630
1206791 5630
1206791 5630
1206791 5630
1206791 6202
1206791 6586
1206791 658...

result:

ok 2000000 lines

Test #9:

score: 10
Accepted
time: 1308ms
memory: 52292kb

input:

2000000
1 0 933589 540
1 0 1332805 804
1 1 726913 60
1 0 582566 540
1 0 1541647 266
1 0 61185 227
1 0 44006 722
2 1
1 1 1100826 318
1 1 1583347 709
1 1 488319 941
2 10
1 0 1929473 528
2 13
1 1 1077416 855
1 0 1182411 885
1 0 1667425 768
1 1 1383821 403
1 0 187972 894
1 1 1583116 592
1 1 242066 187
2...

output:

Peace
Peace
Peace
726913 120
726913 120
726913 120
726913 120
726913 120
726913 756
726913 2174
726913 2174
488319 1898
488319 1898
488319 1898
726913 2466
726913 2466
726913 2466
1077416 2978
488319 3686
726913 4456
726913 4456
726913 4456
1077416 4766
1077416 4766
1077416 4766
726913 5090
726913 6...

result:

ok 2000000 lines

Test #10:

score: 10
Accepted
time: 1371ms
memory: 55884kb

input:

2000000
1 0 267659481 924
1 1 211034569 948
1 1 760144421 564
1 1 657639999 860
1 0 180151690 350
2 4
1 1 99406176 793
2 3
1 1 81357121 972
1 0 260132781 642
1 0 7161061 191
1 1 245955169 633
1 1 387566565 485
1 1 72982881 592
1 1 141574651 711
1 1 88299089 143
1 0 355273696 723
1 1 19210825 454
1 0...

output:

Peace
Peace
760144421 1128
657639999 1848
657639999 2548
760144421 1128
760144421 1128
211034569 700
211034569 700
211034569 700
211034569 1082
245955169 1082
245955169 1082
245955169 1082
245955169 1082
245955169 1082
245955169 1082
245955169 1082
211034569 3016
211034569 3942
211034569 3942
211034...

result:

ok 2000000 lines

Extra Test:

score: 0
Extra Test Passed