QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#748930 | #7787. Maximum Rating | podys | WA | 4ms | 21868kb | C++14 | 2.5kb | 2024-11-14 22:00:38 | 2024-11-14 22:00:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int a[200005];
class tre{
public:
const int N=2e5+5;
vector<int> sum,ls,rs;
// int sum[N * 2], ls[N * 2], rs[N * 2];
tre(){
sum=vector<int>(N*2);
ls=vector<int>(N*2);
rs=vector<int>(N*2);
}
// root 表示整棵线段树的根结点;cnt 表示当前结点个数
int cnt=0, root=0;
// 用法:update(root, 1, n, x, f); 其中 x 为待修改节点的编号
void update(int& p, int s, int t, int x, int f) { // 引用传参
if (!p) p = ++cnt; // 当结点为空时,创建一个新的结点
if (s == t) {
sum[p] += f;
return;
}
int m = s + ((t - s) >> 1);
if (x <= m)
update(ls[p], s, m, x, f);
else
update(rs[p], m + 1, t, x, f);
sum[p] = sum[ls[p]] + sum[rs[p]]; // pushup
}
// 用法:query(root, 1, n, l, r);
int query(int p, int s, int t, int l, int r) {
if (!p) return 0; // 如果结点为空,返回 0
if (s >= l && t <= r) return sum[p];
int m = s + ((t - s) >> 1), ans = 0;
if (l <= m) ans += query(ls[p], s, m, l, r);
if (r > m) ans += query(rs[p], m + 1, t, l, r);
return ans;
}
};
void solve(){
tre t1,t2;
int n,q;
cin>>n>>q;
int sum=0;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]<=0){
sum-=a[i];
}else{
t1.update(t1.root, 1, n, a[i], a[i]);
t2.update(t2.root, 1, n, a[i], 1);
}
}
while(q--){
int x,v;
cin>>x>>v;
if(a[x]<=0){
sum+=a[x];
}else{
t1.update(t1.root, 1, n, a[x], -a[x]);
t2.update(t2.root, 1, n, a[x], -1);
}
a[x]=v;
if(v<=0){
sum-=v;
}else{
t1.update(t1.root, 1, n, v, v);
t2.update(t2.root, 1, n, v, 1);
}
int l=0,r=1e16;
while(l<r){
int mid=l+r+1>>1;
if(t1.query(t1.root, 1, n, 1, mid)<=sum){
l=mid;
}else{
r=mid-1;
}
}
cout<<t2.query(t2.root,1,n,1,l)+1<<endl;
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
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: 4ms
memory: 21856kb
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: 21692kb
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: 4ms
memory: 21868kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 21732kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 21716kb
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'