QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#629835 | #7787. Maximum Rating | Mrlaolu# | WA | 1ms | 4264kb | C++20 | 1.8kb | 2024-10-11 15:07:07 | 2024-10-11 15:07:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
using LL = long long;
const int N = 201000;
int n, m, Q;
int ans;
struct node{
int l, r;
LL sum, cnt;
}tr[N * 60];
int rt, idx;
int a[N];
void push_up(int u){
tr[u].sum = tr[tr[u].l].sum + tr[tr[u].r].sum;
tr[u].cnt = tr[tr[u].l].cnt + tr[tr[u].r].cnt;
}
void modify(int &u, int l, int r, int pos, int x){
if(!u) u = ++ idx;
if(l == r){
tr[u].cnt += x;
tr[u].sum += pos * x;
return;
}
int mid = l + r >> 1;
if(pos <= mid) modify(tr[u].l, l, mid, pos, x);
else modify(tr[u].r, mid + 1, r, pos, x);
push_up(u);
}
int query(int u, int l, int r, LL tot){
if(!u) return 0;
if(l == r){
return min(tot / r, tr[u].cnt);
}
int mid = l + r >> 1;
if(tot >= tr[u].sum){
return tr[u].cnt + query(tr[u].r, mid + 1, r, tot - tr[u].sum);
}
return query(tr[u].l, l, mid, tot);
}
void solve() {
cin >> n >> Q;
for(int i = 1; i <= n; i ++) cin >> a[i];
LL totf = 0;
int nx = 1e9;
for(int i = 1; i <= n; i ++){
if(a[i] <= 0) totf += - a[i];
else{
modify(rt, 1, nx, a[i], 1);
}
}
while(Q --){
int pos, x;
cin >> pos >> x;
if(a[pos] > 0) modify(rt, 1, nx, a[pos], -1);
else totf += a[pos];
if(x > 0) modify(rt, 1, nx, x, 1);
else totf -= x;
a[pos] = x;
cout << query(rt, 1, nx, totf) + 1 << "\n";
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int _ = 1;
//cin >> _;
while(_--) {
solve();
}
}
/*
3 5
1 2 3
3 4
2-2
1-3
3 1
2 1
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3652kb
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: 3588kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3668kb
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:
946 65 252 410 915 592 983 487 343 899 809 432 586 587 139 464 804 84 476 699 504 149 579 352 375 856 545 166 140 657 568 509 275 710 873 430 537 879 301 1 298 970 923 510 984 642 55 879 941 344 464 788 917 994 571 610 491 442 926 101 986 840 624 613 425 345 816 423 275 221 317 113 386 116 469 260 4...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
1000 1000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...
output:
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 ...
result:
ok 1000 numbers
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 4264kb
input:
1000 1000 -485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...
output:
2 3 4 6 7 8 11 14 15 16 17 17 18 23 24 26 28 32 34 35 36 40 41 43 44 45 43 45 47 51 54 55 58 59 61 65 66 67 73 77 83 86 88 89 90 91 92 93 94 95 96 98 98 100 105 106 107 109 110 111 112 114 114 115 116 122 123 124 125 126 128 130 135 136 137 139 140 140 141 146 147 148 150 151 152 153 156 157 159 160...
result:
wrong answer 4th numbers differ - expected: '5', found: '6'