QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880836#7787. Maximum RatingRose_LuWA 2ms9812kbC++142.0kb2025-02-03 21:22:392025-02-03 21:22:40

Judging History

This is the latest submission verdict.

  • [2025-02-03 21:22:40]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 9812kb
  • [2025-02-03 21:22:39]
  • Submitted

answer

#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;

int n, q, tot;
ll S;
ll a[N], b[N];
struct zx { ll id, v; } c[N];

namespace Seg {
	#define ls (x << 1)
	#define rs (x << 1 | 1)
	
	struct Segment {
		ll l, r, data, cnt;
	} t[N << 2];
	
	void pushup (int x) {
		t[x].data = t[ls].data + t[rs].data;
		t[x].cnt = t[ls].cnt + t[rs].cnt;
	}
	
	void build (int x, int l, int r) {
		if (l > r) return;
		t[x].l = l, t[x].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build(ls, l, mid), build (rs, mid + 1, r);
	}
	
	void modify (int x, int X, int v, int k) {
		int l = t[x].l, r = t[x].r, mid = (l + r) >> 1;
		if (l == r) {
			t[x].cnt += k, t[x].data += v;
			return;
		}
		if (X <= mid) modify(ls, X, v, k);
		else modify(rs, X, v, k);
		pushup(x);
	}
	
	int query (int x, int v) {
		int l = t[x].l, r = t[x].r;
		if (t[x].data <= v) return t[x].cnt;
		if (l == r) return min(v / b[t[x].l], t[x].cnt);
		if (t[ls].data > v) return query(ls, v);
		else return t[ls].cnt + query(rs, v - t[ls].data);
	}
}

signed main () {
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (a[i] <= 0) S += a[i];
		else b[++tot] = a[i];
	}
	for (int i = 1; i <= q; ++i) {
		cin >> c[i].id >> c[i].v;
		if (c[i].v > 0) b[++tot] = c[i].v;
	}
	Seg::build (1, 1, tot);
	sort(b + 1, b + tot + 1);
	tot = unique(b + 1, b + tot + 1) - b - 1;
	for (int i = 1; i <= n; ++i)
		if (a[i] > 0) {
			a[i] = lower_bound(b + 1, b + tot + 1, a[i]) - b;
			Seg::modify(1, a[i], b[a[i]], 1);
		}
	for (int i = 1; i <= q; ++i) 
		if (c[i].v > 0)
			c[i].v = lower_bound(b + 1, b + tot + 1, c[i].v) - b;
	for (int i = 1; i <= q; ++i) {
		if (a[c[i].id] > 0) Seg::modify(1, a[c[i].id], -b[a[c[i].id]], -1);
		else S -= a[c[i].id];
		if (c[i].v > 0) Seg::modify(1, c[i].v, b[c[i].v], 1);
		else S += c[i].v;
		a[c[i].id] = c[i].v;
		cout << Seg::query(1, -S) + 1 << endl;
	} 
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 7764kb

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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

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: -100
Wrong Answer
time: 0ms
memory: 9728kb

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
4
4
4
-44
-291
-572
-697
-1397
-1397
-1460
-1634
10
8
7
1
-627
-1471
11
8
7
2
-654
-697
-697
-1417
-1833
12
8
8
4
-647
-1121
-1268
15
11
8
-122
-819
-1359
-1729
13
11
5
3
-71
-89
-760
-1586
17
17
15
15
11
10
-163
-792
-1222
-1598
16
16
10
4
-583
-1217
16
16
16
13
9
-168
-904
-1497
18
17
17
12
...

result:

wrong answer 4th numbers differ - expected: '5', found: '4'