QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603413#7787. Maximum Ratingwsxcb#WA 3ms11808kbC++172.1kb2024-10-01 16:26:342024-10-01 16:26:35

Judging History

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

  • [2024-10-01 16:26:35]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11808kb
  • [2024-10-01 16:26:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
const int N = 4e5 + 10;
//#define int long long

int lowbit(int x) {
	return  x & (-x);
}

struct BIT {
	ll a[N];
	void add(int x, int k) {
		for (int i = x; i < N; i += lowbit(i))
			a[i] += k;
	}
	int get(int x) {
		ll ans = 0;
		for (int i = x; i; i -= lowbit(i)) {
			ans += a[i];
		}
		return ans;
	}
} t1, t2;
int n, q, cnt = 0;
int a[N], b[N];
ll s1 = 0, c2 = 0, c1 = 0;

void solve() {

	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] > 0) {
			b[++cnt] = a[i];
			c2++;
		} else if (a[i] < 0) {
			s1 += abs(a[i]);
			c1++;
		}
	}
	vector<pair<int, int>>ask(q + 1);
	for (int i = 1; i <= q; i++) {
		cin >> ask[i].first >> ask[i].second;
		if (ask[i].second > 0)
			b[++cnt] = ask[i].second;
	}
	sort(b + 1, b + 1 + cnt);
	int len = unique(b + 1, b + 1 + cnt) - b - 1;
	for (int i = 1; i <= n; i++) {
		int pos = lower_bound(b + 1, b + 1 + len, a[i]) - b;
		if (a[i] > 0) {
			t1.add(pos, 1);
			t2.add(pos, a[i]);
		}
	}
	for (int _ = 1; _ <= q; _++) {
		auto [p1, x] = ask[_];
		int pos = lower_bound(b + 1, b + 1 + len, x) - b;
		if (x > 0) {
			t1.add(pos, 1);
			t2.add(pos, x);
			c2++;
		} else if (x < 0)
			s1 += abs(x);
		if (a[p1] > 0) {
			int pos = lower_bound(b + 1, b + 1 + len, a[p1]) - b;
			//cout << pos << ' ';
			t1.add(pos, -1);
			t2.add(pos, -a[p1]);
			c2--;
		} else if (a[p1] < 0)
			s1 -= abs(a[p1]);
		a[p1] = x;
		//cout << s1 << ' ';
		int l = 1, r = len, p2 = -1;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (t2.get(mid) >= s1) {
				p2 = mid;
				r = mid - 1;
			} else
				l = mid + 1;
		}
		if (p2 == -1) {
			cout << c2 + 1 << '\n';
			continue;
		}
		int cnt2 = t1.get(p2);
		ll sum = t2.get(p2);
		//cout << sum << ' ' << cnt2 << ' ';
		sum -= s1;
		cnt2 -= (sum + b[p2] - 1) / b[p2];
		r = c2, l = c2 - cnt2;
		//cout << l << ' ' << r << ' ';
		cout << r - l + 1 << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11748kb

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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

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

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:

wrong answer 746th numbers differ - expected: '505', found: '506'