QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#669705 | #7787. Maximum Rating | blackfrog | WA | 1ms | 7824kb | C++14 | 1.5kb | 2024-10-23 19:26:48 | 2024-10-23 19:26:49 |
Judging History
answer
#include<iostream>
using namespace std;
const long long N = 2e5+10;
const long long L = -1e9-10, R = 1e9+10;
long long n,q, tot = 1, rt = 1;
long long t[N<<7], siz[N<<7], ls[N<<7], rs[N<<7], a[N];
void pushup(long long p){
t[p] = t[ls[p]] + t[rs[p]];
siz[p] = siz[ls[p]] + siz[rs[p]];
}
void insert(long long &p, long long l, long long r, long long x, long long c){
if(p == 0)p = ++tot;
if((long long)(r - l) == 1ll){
t[p] += x * c;
siz[p] += c;
return;
}
long long mid = (l + r) >> 1;
if(x < mid)insert(ls[p], l, mid, x, c);
else insert(rs[p], mid, r, x, c);
pushup(p);
}
long long query(long long &p, long long s){
if(s >= t[p])return siz[p];
if(s > t[ls[p]])return siz[ls[p]] + query(rs[p], s - t[ls[p]]);
if(s == t[ls[p]])return siz[ls[p]];
else return query(ls[p], s);
}
long long neg;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>q;
for(long long i = 1;i<=n;i++){
cin>>a[i];
if(a[i] > 0){
insert(rt, L, R, a[i], 1);
}
if(a[i] < 0){
neg -= a[i];
}
}
while(q--){
long long x, v;
cin>>x>>v;
if(a[x] > 0){
insert(rt, L, R, a[x], -1);
}
else{
neg += a[x];
}
a[x] = v;
if(v > 0){
insert(rt, L, R, v, 1);
}
else{
neg -= v;
}
cout<<query(rt, neg) + 1<<'\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7812kb
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: 7724kb
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: 7660kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 7824kb
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'