QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#712972#7787. Maximum RatingsurenjamtsWA 11ms53588kbC++173.9kb2024-11-05 17:40:142024-11-05 17:40:14

Judging History

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

  • [2024-11-05 17:40:14]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:53588kb
  • [2024-11-05 17:40:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
const int N = 400045;
map<int,int> mp,mpp;
bool tmp[2*N], ex[N*2], og[N];
int tree[N*8], ztree[N*8], lst[2*N];
vector <int> v;
void build( int l, int r, int node ){
	if( r < l )
		return;
	if( l == r ){
		if( ex[l] ){
			tree[node] = v[l];
		}else{
			ztree[node] ++;
		}
		return;
	}
	int mid = (l+r)/2;
	build( l, mid, node*2 );
	build( mid+1, r, node*2+1 );
	tree[node] = tree[node*2]+tree[node*2+1];
	ztree[node] = ztree[node*2]+ztree[node*2+1];
}
void add(int l, int r, int node, int idx ){
	if( idx < l || r < idx )
		return;
	if( l == r ){
		tree[node] = v[l];
		ztree[node] = 0;
		return;
	}
	int mid = (l+r)/2;
	add(l,mid,node*2,idx);
	add(mid+1,r,node*2+1,idx);
	tree[node] = tree[node*2]+tree[node*2+1];
	ztree[node] = ztree[node*2]+ztree[node*2+1];
}
void delet(int l, int r, int node, int idx ){
	if( idx < l || r < idx )
		return;
	if( l == r ){
		tree[node] = 0;
		ztree[node] = 1;
		return;
	}
	int mid = (l+r)/2;
	delet(l,mid,node*2,idx);
	delet(mid+1,r,node*2+1,idx);
	tree[node] = tree[node*2]+tree[node*2+1];
	ztree[node] = ztree[node*2]+ztree[node*2+1];
}
int get_sum(int l, int r, int L, int R, int node ){
	if( r < L || R < l ){
		return 0;
	}
	if( L <= l && r <= R ){
		return tree[node];
	}
	int mid = (l+r)/2;
	return get_sum( l, mid, L, R, node*2 ) + get_sum( mid+1,r, L,R,node*2+1 );
}
int get_zero( int l, int r, int L, int R, int node  ){
	if( r < L || R < l ){
		return 0;
	}
	if( L <= l && r <= R ){
		return ztree[node];
	}
	int mid = (l+r)/2;
	return get_zero( l, mid, L, R, node*2 ) + get_zero( mid+1,r, L,R,node*2+1 );
}
signed main(){
//	ios_base::sync_with_stdio(NULL);
//	cin.tie(NULL);
//	cout.tie(NULL);
	int n, q, a[N], b[N], m[2*N], mm[2*N], que[2*N], id[2*N];
	cin >> n >> q;
	vector < pair<int,int> > vc, query;
	vc.pb( {-1,-1} );
	v.pb(-1);
	int neg_sum = 0, h = 1;
	int hsh[2*N];
	for(int i = 1; i <= n; i ++ ){
		cin >> a[i];
		b[i] = a[i];
		if( a[i] <= 0 )
			neg_sum += a[i];
		else{
			og[ i ] = 1;
			tmp[h] = 1;
			m[ h ] = i;
			hsh[i] = h;
			vc.pb( {a[i],h++} );
		}
	}
	pair<int,int> p[N];
	for(int i = 1; i <= q; i ++ ){
		cin >> p[i].F >> p[i].S;
		if( p[i].S > 0 ){
			que[ h ] = i;
			vc.pb( {p[i].S,h++} );
		}
	}
	sort( vc.begin(), vc.end() );
	for(int i = 1; i < vc.size(); i ++ ){
		v.pb( vc[i].F );
		if( tmp[vc[i].S] ){
			ex[i] = 1;
			mm[ m[vc[i].S] ] = i;
		}
		else{
			id[que[ vc[i].S ]] = i;
		}
	}
	n = vc.size()-1;
	build( 1, n, 1 );
	int f, s;
	for(int i = 1; i <= q; i ++ ){
		bool gege = false;
		if( b[ p[i].F ] <= 0 ){
			f = b[ p[i].F ];
		}else{
			if( og[ p[i].F ] ){
				og[ p[i].F ] = 0;
				f = mm[hsh[ p[i].F ]];
			}else{
				f = lst[p[i].F];
			}
		}
		if( p[i].S <= 0 ){
			s = p[i].S;
		}else{
			s = id[ i ];
//			cout << "query" << i << ":" << p[i].F << "<-" << s << "\n";
			lst[ p[i].F ] = s;
		}
		
		b[ p[i].F ] = p[i].S;
		query.pb( {f,s} );
	}
//	cout << "tree:\n";
//	for(int i = 1; i <= 9; i ++ ){
//		cout << i << ":" << tree[i] << "\n";
//	}
//	return 0;
	for(int i = 0; i < query.size(); i ++ ){
//		cout << "QUERY" << i+1 << "\n";
//		cout << f << " " << s << "\n";
		int f = query[i].F, s = query[i].S;
		if( f <= 0 ){
			neg_sum -= f;
		}else{
			delet( 1, n, 1, f );
		}
		if( s <= 0 ){
			neg_sum += s;
		}else{
			add( 1, n, 1, s );
		}
		int l = 1, r = n;
		int k = 0;
//		cout << "neg_sum " << neg_sum << "\n";
		while( l <= r ){
//			cout << "range:" << l << " " << r << "\n";
			int mid = (l+r)/2;
			if( get_sum( 1,n,1,mid,1 ) <= abs(neg_sum) ){
				k = mid-get_zero(1,n,1,mid,1);
//				cout << mid << " " << get_sum( 1,n,1,mid,1 ) << " " << get_zero(1,n,1,mid,1) << "\n";
				l = mid+1;	
			}else{
				r = mid-1;
			}
		}
		cout << k+1 << "\n";
	}
}

詳細信息

Test #1:

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

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

1
2
2
2
3

result:

ok 5 number(s): "1 2 2 2 3"

Test #2:

score: 0
Accepted
time: 7ms
memory: 53452kb

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
1

result:

ok 5 number(s): "1 2 1 2 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 53404kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 4ms
memory: 47404kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 51704kb

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 4ms
memory: 51464kb

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 7ms
memory: 49500kb

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

2
3
4
5
6
7
8
9
10
11
12
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
51
52
53
54
55
56
57
58
59
60
60
61
62
63
64
65
65
66
67
68
69
70
71
72
73
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
88
89
90
91
92
92
93
94
95
96...

result:

ok 1000 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 51568kb

input:

1000 1000
692178227 662595541 345515063 991152011 835514013 25683568 123726285 66892783 865428606 354216625 814472013 533064716 948349754 361975669 37940082 869044119 662812642 803704097 146471883 707522800 739525519 193714172 427089913 397196213 189039234 246429967 813126715 687459477 71112534 8404...

output:

43
51
56
64
65
74
75
86
87
95
101
108
113
120
128
133
138
139
139
144
145
148
151
156
156
158
160
161
166
168
172
174
178
181
184
187
187
189
191
194
198
202
205
206
207
209
208
208
212
213
213
212
215
219
220
221
222
223
225
228
231
234
235
235
236
236
238
238
241
243
244
244
247
247
247
248
249
25...

result:

ok 1000 numbers

Test #9:

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

input:

1000 1000
574468116 94882719 344585092 303636576 860857354 553186159 965991069 700277773 418699098 303119379 321049044 311046263 246185690 843955069 991766564 157610065 845367822 6325150 14241791 204057976 158548256 378251315 960460247 976973909 903759916 617675386 774999095 700647307 182260243 3951...

output:

1
1
1
44
62
62
62
62
62
62
62
63
75
86
86
94
94
94
94
94
94
101
106
110
109
109
110
110
114
118
120
120
125
133
137
142
149
151
151
154
158
163
164
164
166
171
166
171
171
176
178
178
178
182
184
189
191
192
192
193
194
194
199
199
200
200
200
201
201
202
202
203
203
203
203
204
205
209
211
213
216
...

result:

ok 1000 numbers

Test #10:

score: 0
Accepted
time: 11ms
memory: 51588kb

input:

1000 1000
751725297 937235315 680091610 26186557 254796915 744252261 881884780 923597346 266936883 546989425 417560660 89027810 544021626 957338248 904123848 814772232 101551928 545382694 250607919 995560445 577570993 931384678 862426799 261784312 954917086 283888096 73307963 303769720 219779023 411...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 1000 numbers

Test #11:

score: -100
Wrong Answer
time: 7ms
memory: 51548kb

input:

1000 1000
-508752650 194148329 -801456523 151112987 832369235 -688290588 806491091 836936846 -122281173 356992850 -568184583 -516872363 165777265 -971767664 709095458 287512288 -240509024 222892519 809890680 -240691276 -160995890 -941338137 -110422024 -171235654 137147409 269779505 791942508 8316469...

output:

502
502
502
503
503
502
502
503
503
504
504
504
504
505
505
506
506
506
506
507
507
507
506
506
505
504
504
504
504
504
504
504
504
504
505
505
505
505
505
505
505
506
507
507
507
508
507
507
508
508
508
508
509
508
509
509
510
511
511
512
512
513
513
512
511
512
512
512
512
513
513
514
514
514
514
...

result:

wrong answer 2nd numbers differ - expected: '501', found: '502'