QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#633507 | #7787. Maximum Rating | the_fool# | WA | 1ms | 3860kb | C++20 | 2.5kb | 2024-10-12 15:37:37 | 2024-10-12 15:37:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ll = long long;
struct fenwick {
int n;
vector<LL> s;
fenwick(int _n) {
n = _n;
s.assign(n + 1, {});
}
int lowbit(int x) {
return x & -x;
}
void add(int x, int v) {
while (x <= n) {
s[x] += v;
x += lowbit(x);
}
}
LL query(int x) {
LL res = 0;
while (x >= 1) {
res += s[x];
x -= lowbit(x);
}
return res;
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<int> a(n + 1), b(q + 1), c(q + 1), all{0};
for (int i = 1; i <= n; i++) {
cin >> a[i];
all.emplace_back(a[i]);
}
for (int i = 1; i <= q; i++) {
cin >> b[i] >> c[i];
all.emplace_back(c[i]);
}
sort(all.begin() + 1, all.end());
all.erase(unique(all.begin() + 1, all.end()), all.end());
int cnt = all.size();
fenwick bit1(cnt), bit2(cnt);
auto getid = [&](int x) {
return lower_bound(all.begin() + 1, all.end(), x) - all.begin();
};
auto del = [&](int x) {
int id = getid(x);
bit1.add(id, -x);
bit2.add(id, -1);
};
auto add = [&](int x) {
int id = getid(x);
bit1.add(id, x);
bit2.add(id, 1);
};
auto findFirst = [&](LL sum) {
int l = 1, r = cnt;
int pos = cnt + 1;
while (l <= r) {
int m = (l + r) >> 1;
if (bit1.query(m) >= sum) {
pos = m;
r = m - 1;
} else {
l = m + 1;
}
}
--pos;
return bit2.query(pos);
};
LL sum = 0;
for (int i = 1; i <= n; i++) {
if (a[i] > 0) {
add(a[i]);
} else {
sum += -a[i];
}
}
for (int i = 1; i <= q; i++) {
int x = a[b[i]], y = c[i];
if (x <= 0) sum -= -x;
else del(x);
if (y > 0) add(y);
else sum += -y;
a[b[i]] = y;
int res2 = findFirst(sum);
cout << res2 + 1 << "\n";
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef Debug
assert(freopen("in.txt", "r", stdin));
assert(freopen("out.txt", "w", stdout));
#endif
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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: 3568kb
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: 3860kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3828kb
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'