QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880818#7787. Maximum RatingRose_LuRE 0ms7760kbC++141.9kb2025-02-03 21:11:152025-02-03 21:11:16

Judging History

This is the latest submission verdict.

  • [2025-02-03 21:11:16]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 7760kb
  • [2025-02-03 21:11:15]
  • 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) {
		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: 0ms
memory: 5656kb

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

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: -100
Runtime Error

input:

1 1
-1000000000
1 -1000000000

output:


result: