QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635548 | #7787. Maximum Rating | yell | WA | 1ms | 3820kb | C++20 | 1.9kb | 2024-10-12 20:08:15 | 2024-10-12 20:08:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e5 + 100;
const int INF = 1e9;
int tot = 1;
struct node {
int lson, rson, num;
LL sum;
} seg[N * 120];
#define ls seg[id].lson
#define rs seg[id].rson
void pushdown(int id) {
if (!ls) ls = ++tot;
if (!rs) rs = ++tot;
}
void pushup(int id) {
seg[id].sum = seg[ls].sum + seg[rs].sum;
seg[id].num = seg[ls].num + seg[rs].num;
}
void modify(int id, int l, int r, int pos, int val) {
if (l == r) {
seg[id].num += val;
seg[id].sum += pos * val;
return;
}
pushdown(id);
int mid = (l + r) / 2;
if (pos <= mid) {
modify(ls, l, mid, pos, val);
} else {
modify(rs, mid + 1, r, pos, val);
}
pushup(id);
}
int query(int id, int l, int r, LL sum) {
if (l == r) {
return (sum <= 0 ? 0 : seg[id].num);
}
int mid = (l + r) / 2;
if (seg[rs].sum >= sum) {
return query(rs, mid + 1, r, sum);
} else {
return query(ls, l, mid, sum - seg[rs].sum) + seg[rs].num;
}
}
void solve() {
int n, q;
cin >> n >> q;
vector<int> a(n + 1);
LL sum = 0;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] > 0) {
modify(1, 1, INF, a[i], 1);
cnt++;
}
}
while (q--) {
int idx, val;
cin >> idx >> val;
if (a[idx] > 0) {
modify(1, 1, INF, a[idx], -1);
cnt--;
}
if (val > 0) {
modify(1, 1, INF, val, 1);
cnt++;
}
sum = sum - a[idx] + val;
a[idx] = val;
cout << cnt - query(1, 1, INF, sum) + 1 << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
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: 3560kb
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: 3564kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3664kb
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'