QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768877 | #7787. Maximum Rating | Rubyonly# | WA | 2ms | 12128kb | C++14 | 1.7kb | 2024-11-21 15:01:05 | 2024-11-21 15:01:05 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 50, INF = 0x7f7f7f7f;
inline int read() {
int x = 0, w = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return x * w;
}
int n, m, len;
int a[maxn], b[maxn], c[maxn];
int num[maxn];
ll sum, tree[maxn];
map<int, int> mp;
struct Ask {
int x, val;
} q[maxn];
void Insert(int x, int cnt, int val) {
for (; x <= len; x += x & -x)
num[x] += cnt, tree[x] += val;
}
ll Query(int t, int x, ll ans = 0) {
if (t == 0) {
for (; x; x -= x & -x)
ans += num[x];
} else {
for (; x; x -= x & -x)
ans += tree[x];
}
return ans;
}
void Modify(int x, int val) {
if (a[x] < 0) sum += a[x];
if (a[x] > 0) Insert(mp[a[x]], -1, -a[x]);
a[x] = val;
if (a[x] < 0) sum -= a[x];
if (a[x] > 0) Insert(mp[a[x]], 1, a[x]);
}
ll Calc() {
int l = 1, r = len;
while (l <= r) {
int mid = (l + r) >> 1;
if (Query(1, mid) > sum) r = mid - 1;
else l = mid + 1;
}
return Query(0, r) + 1;
}
int main() {
n = read(), m = read();
for (int i = 1; i <= n; i ++) {
c[i] = read();
if (c[i] > 0) b[++ len] = c[i];
}
for (int i = 1; i <= m; i ++) {
q[i].x = read(), q[i].val = read();
if (q[i].val > 0) b[++ len] = q[i].val;
}
sort(b + 1, b + len + 1), len = unique(b + 1, b + len + 1) - b - 1;
for (int i = 1; i <= len; i ++) mp[b[i]] = i;
for (int i = 1; i <= n; i ++) Modify(i, c[i]);
for (int i = 1; i <= m; i ++)
Modify(q[i].x, q[i].val), printf("%lld\n", Calc());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11976kb
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: 11980kb
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: 12128kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 10000kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 11976kb
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:
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 1 1 1 1 1 ...
result:
wrong answer 1st numbers differ - expected: '946', found: '1'