QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880828#7787. Maximum RatingRose_LuWA 1ms7760kbC++141.9kb2025-02-03 21:17:562025-02-03 21:17:57

Judging History

This is the latest submission verdict.

  • [2025-02-03 21:17:57]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7760kb
  • [2025-02-03 21:17:56]
  • Submitted

answer

#include <iostream>
#include <algorithm>

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

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

namespace Seg {
	#define ls (x << 1)
	#define rs (x << 1 | 1)
	
	struct Segment {
		int 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);
	}
}

int 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: 1ms
memory: 5716kb

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: 1ms
memory: 5712kb

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

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

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

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

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
8
9
-572
-697
-1397
-1397
-1460
-1634
15
8
17
18
-627
-1471
21
22
10
24
25
26
26
-1417
-1833
29
30
31
32
33
-1121
35
36
37
38
29
-819
-1359
-1729
43
44
45
3
24
25
26
27
51
51
52
53
54
55
29
30
30
59
60
60
61
62
63
20
65
65
66
46
68
69
70
-1497
72
73
73
74
75
29
29
29
79
80
81
-1141
-1392...

result:

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