QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749032#7787. Maximum RatingpodysRE 0ms15484kbC++142.7kb2024-11-14 22:25:332024-11-14 22:25:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 22:25:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:15484kb
  • [2024-11-14 22:25:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int a[200005];
const int N=2e5+5;
class tre{
public:
    vector<int> sum,ls,rs,ct;
    // 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);
        ct=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,int g) {  // 引用传参
        if (!p) p = ++cnt;  // 当结点为空时,创建一个新的结点
        if (s == t) {
            sum[p] += f;
            ct[p] += g;
            return;
        }
        int m = s + ((t - s) >> 1);
        if (x <= m)
            update(ls[p], s, m, x, f,g);
        else
            update(rs[p], m + 1, t, x, f,g);
        sum[p] = sum[ls[p]] + sum[rs[p]];  // pushup
        ct[p] = ct[ls[p]] + ct[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;
    }
    int check(int p,int s,int t,int &now){
        if (!p) return 0;  // 如果结点为空,返回 0
        if(s==t && now<=sum[p]){
            int ret=now/(sum[p]/ct[p]);
            now-=ret*sum[p];
            return ret;
        }
        if(sum[p]<=now){
            now-=sum[p];
            return ct[p];
        }
        int m = s + ((t - s) >> 1), ans = 0;
        ans+=check(ls[p],s,m,now);
        ans+=check(rs[p],m+1,t,now);
        return ans;
    }
};
void solve(){
    tre t1;
    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],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],-1);
        }
        a[x]=v;
        if(v<=0){
            sum-=v;
        }else{
            t1.update(t1.root, 1, n, v, v,1);
        }
        int tmp=sum;
        cout<<t1.check(t1.root,0,n,tmp)+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: 0ms
memory: 15484kb

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: -100
Runtime Error

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:


result: