QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#674103 | #7787. Maximum Rating | Calculatelove# | WA | 1ms | 5924kb | C++14 | 1.6kb | 2024-10-25 13:53:01 | 2024-10-25 13:53:02 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long s64;
const int N = 200100;
const int sz = 1e9;
int n, Q;
int a[N];
s64 sum;
namespace SGT {
const int pond = 10001000;
int nClock, root;
struct node {
int lc, rc;
int cnt;
s64 sum;
} t[pond];
void insert(int &p, int l, int r, int x, int type) {
if (!p) p = ++ nClock;
t[p].cnt += type, t[p].sum += x * type;
if (l == r) return;
int mid = (l + r) >> 1;
if (x <= mid)
insert(t[p].lc, l, mid, x, type);
else
insert(t[p].rc, mid + 1, r, x, type);
}
int ask(int p, int l, int r, s64 k) {
if (l == r) return std::min((s64)t[p].cnt, k / l);
int mid = (l + r) >> 1;
if (k <= t[t[p].rc].sum)
return ask(t[p].rc, mid + 1, r, k);
else
return ask(t[p].lc, l, mid, k - t[t[p].rc].sum) + t[t[p].rc].cnt;
}
}
void add(int x) {
if (!x) return;
sum += x;
if (x > 0) SGT::insert(SGT::root, -sz, sz, x, +1);
}
void dec(int x) {
if (!x) return;
sum -= x;
if (x > 0) SGT::insert(SGT::root, -sz, sz, x, -1);
}
int main() {
scanf("%d%d", &n, &Q);
for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i ++) add(a[i]);
while (Q --) {
int x, v;
scanf("%d%d", &x, &v);
dec(a[x]), add(a[x] = v);
printf("%d\n", SGT::t[SGT::root].cnt - SGT::ask(SGT::root, -sz, sz, sum - 1) + (sum <= 0));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
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: 3872kb
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: 1ms
memory: 5924kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3812kb
input:
1 1 -1000000000 1 -1000000000
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'