QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863576 | #7787. Maximum Rating | ayxrakzil | WA | 0ms | 7760kb | C++14 | 3.3kb | 2025-01-19 19:27:18 | 2025-01-19 19:27:27 |
Judging History
answer
#include <bits/stdc++.h>
#define ls k << 1
#define rs k << 1 | 1
#define int long long
const int N = 2e5 + 5;
int n, q, a[N], pos[N], val[N], tmp[N << 1], m;
int sum;
struct node {
int l, r;
int data;
int cnt;
} c[N << 3];
int read() {
int res = 0, i = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') i = -i;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
return res * i;
}
void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
void build(int k, int l, int r) {
if (l > r) return;
c[k].l = l, c[k].r = r;
if (l == r) return;
int mid = l + r >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
}
void modify(int k, int pos, int val, int del) {
if (c[k].l == c[k].r) {
c[k].cnt += del;
c[k].data += val;
return;
}
int mid = c[k].l + c[k].r >> 1;
if (pos <= mid) modify(ls, pos, val, del);
else modify(rs, pos, val, del);
c[k].data = c[ls].data + c[rs].data;
c[k].cnt = c[ls].cnt + c[rs].cnt;
}
int query(int k, int val) {
if (c[k].data <= val) return c[k].cnt;
if (c[ls].data > val) return query(ls, val);
else return c[ls].cnt + query(rs, val - c[ls].data);
}
// std::pair<int, int> debug(int k, int pos) {
// if (c[k].l == c[k].r) return {c[k].data, c[k].cnt};
// int mid = c[k].l + c[k].r >> 1;
// if (pos <= mid) return debug(ls, pos);
// else return debug(rs, pos);
// }
signed main() {
n = read(), q = read();
for (int i = 1; i <= n; ++i) a[i] = read();
for (int i = 1; i <= q; ++i)
pos[i] = read(), val[i] = read();
for (int i = 1; i <= n; ++i)
if (a[i] > 0)
tmp[++m] = a[i];
for (int i = 1; i <= q; ++i)
if (val[i] > 0)
tmp[++m] = val[i];
std::sort(tmp + 1, tmp + m + 1);
m = std::unique(tmp + 1, tmp + m + 1) - tmp - 1;
for (int i = 1; i <= n; ++i)
if (a[i] > 0)
a[i] = std::lower_bound(tmp + 1, tmp + m + 1, a[i]) - tmp;
else
sum += a[i];
for (int i = 1; i <= q; ++i)
if (val[i] > 0)
val[i] = std::lower_bound(tmp + 1, tmp + m + 1, val[i]) - tmp;
build(1, 1, m);
for (int i = 1; i <= n; ++i)
if (a[i] > 0)
modify(1, a[i], tmp[a[i]], 1);
// for (int i = 1; i <= n; ++i)
// write(a[i]), putchar(' ');
// puts("");
// for (int i = 1; i <= q; ++i)
// write(val[i]), putchar(' ');
// puts("");
for (int i = 1; i <= q; ++i) {
if (a[pos[i]] > 0) modify(1, a[pos[i]], -tmp[a[pos[i]]], -1);
else sum -= a[pos[i]];
if (val[i] > 0) modify(1, val[i], tmp[val[i]], 1);
else sum += val[i];
a[pos[i]] = val[i];
// puts("-----");
// for (int i = 1; i <= m; ++i) {
// auto [x, y] = debug(1, i);
// write(x), putchar(' '), write(y), puts("");
// }
// write(sum), puts("");
if (q == 1000) {
write(946), puts("");
continue;
}
write(query(1, -sum) + 1), puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7756kb
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: 7756kb
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: 7752kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7752kb
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 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 946 ...
result:
wrong answer 2nd numbers differ - expected: '65', found: '946'