QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771320 | #7787. Maximum Rating | mobbb | WA | 1ms | 3804kb | C++20 | 2.0kb | 2024-11-22 11:41:12 | 2024-11-22 11:41:12 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
constexpr int N = 4e5;
int tot = 0,root = 0;
struct info{
ll val, size;
};
struct node{
int ls, rs;
info s;
}tree[N * 4];
#define lson tree[id].ls
#define rson tree[id].rs
info operator + (const info &l, const info &r){
info rt = {0, 0};
if (l.size && r.size){
rt.size = l.size + r.size;
rt.val = l.val + r.val;
}else if (l.size){
rt = l;
}else if (r.size){
rt = r;
}
return rt;
}
void updata(int id){
tree[id].s = tree[lson].s + tree[rson].s;
}
void add(int &id, int l, int r, int pos, int t){
if (!id) {
id = ++tot;
tree[id].s = {0, 0};
tree[id].ls = tree[id].rs = 0;
}
if (l == r){
tree[id].s.val += pos * t;
tree[id].s.size += t;
return;
}
int mid = l + r >> 1;
if (pos <= mid) add(lson, l, mid, pos, t);
if (pos > mid) add(rson, mid + 1, r, pos, t);
updata(id);
}
int query(int id, int l, int r, ll sum){
if (!id){
return 0;
}
int mid = l + r >> 1;
if (tree[lson].s.val > sum){
return query(lson, l, mid, sum);
}else{
ll ans = 0;
ans += tree[lson].s.size;
sum -= tree[lson].s.val;
ans += query(rson, mid + 1, r, sum);
return ans;
}
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
std::vector<int> a(n);
constexpr int inf = 1E9;
ll sum = 0;
for (int i = 0; i < n; i++){
std::cin >> a[i];
if (a[i] <= 0){
sum += -a[i];
}else{
add(root, 1, inf, a[i], 1);
}
}
while (q--){
int x, v;
std::cin >> x >> v;
x--;
if (a[x] > 0){
add(root, 1, inf, a[x], -1);
}else{
sum -= (-a[x]);
}
if (v > 0){
add(root, 1, inf, v, 1);
}else{
sum += (-v);
}
a[x] = v;
// for (int i = 0; i < n; i++){
// std::cout << a[i] << " \n"[i == n - 1];
// }
// std::cerr << "SSS " << tree[1].s.val << ' ' << tree[1].s.size << " " << sum << "\n";
std::cout << query(1, 1, inf, sum) + 1 << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 3732kb
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: 3804kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3592kb
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'