QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#768883 | #7787. Maximum Rating | Rubyonly# | WA | 1ms | 11964kb | C++14 | 1.7kb | 2024-11-21 15:03:20 | 2024-11-21 15:03:20 |
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() {
if (Query(0, len) == 0) return 0;
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11964kb
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: 1ms
memory: 10040kb
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: 9920kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 9924kb
input:
1 1 -1000000000 1 -1000000000
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'