QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777268 | #7787. Maximum Rating | dongfangwuqing | WA | 0ms | 5724kb | C++14 | 2.3kb | 2024-11-24 00:06:46 | 2024-11-24 00:06:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct Node {
long long l, r;
long long cnt;
long long sum;
} tr[32 * 201010];
long long n, q, a[201010], cnt, root, tot = 1;
long long zheng, fu;
void update(long long l, long long r, long long& p, long long num, long long ad) {
if (p == 0) { p = tot++; }
if (l == r) {
tr[p].cnt += ad;
tr[p].sum += 1LL * num * ad;
return;
}
int m = (l + r) / 2;
if (num <= m) { update(l, m, tr[p].l, num, ad); }
else { update(m + 1, r, tr[p].r, num, ad); }
tr[p].cnt = tr[tr[p].l].cnt + tr[tr[p].r].cnt;
tr[p].sum = tr[tr[p].l].sum + tr[tr[p].r].sum;
}
long long find(long long l, long long r, long long p, long long he) {
if (l == r) { return tr[p].cnt; }
int res = 0;
int m = (l + r) / 2;
if (tr[tr[p].l].sum <= he) {
res += tr[tr[p].l].cnt;
he -= tr[tr[p].l].sum;
res += find(m + 1, r, tr[p].r, he);
} else {
return find(l, m, tr[p].l, he);
}
return res;
}
int main() {
cin >> n >> q;
for (int i = 1; i <= n; i++) { cin >> a[i]; }
for (int i = 1; i <= n; i++) {
if (a[i] < 0) { fu -= a[i]; }
if (a[i] > 0) {
zheng += a[i], cnt++;
update(1, 1e9, root, a[i], 1);
}
}
while (q--) {
long long x, v;
cin >> x >> v;
if (a[x] > 0) {
update(1, 1e9, root, a[x], -1);
zheng -= a[x];
cnt--;
if (v < 0) { fu -= v; }
else if (v > 0) { zheng += v; update(1, 1e9, root, v, 1); cnt++; }
} else if (a[x] < 0) {
fu += a[x];
if (v < 0) { fu -= v; }
else if (v > 0) { zheng += v; update(1, 1e9, root, v, 1); cnt++; }
} else {
if (v < 0) { fu -= v; }
else if (v > 0) { zheng += v; update(1, 1e9, root, v, 1); cnt++; }
}
a[x] = v;
if (zheng <= fu) {
cout << cnt + 1 << "\n";
}
else {
long long ma = cnt;
long long tp = find(1, 1e9, root, fu);
long long mi = cnt - tp + 1;
cout << ma - mi + 1 << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5660kb
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: -100
Wrong Answer
time: 0ms
memory: 5724kb
input:
3 5 1 2 3 3 4 2 -2 1 3 3 1 2 1
output:
1 2 1 2 2
result:
wrong answer 5th numbers differ - expected: '1', found: '2'