QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641608#7787. Maximum RatingPepinotWA 0ms3636kbC++201.8kb2024-10-14 21:34:302024-10-14 21:34:33

Judging History

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

  • [2024-10-14 21:34:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-10-14 21:34:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define lowbit(x) (x&(-x))
const int N=2e5+5;
int tt[N];

void add(int x,int k) {
    while(x<N){
        tt[x]+=k;
        x+=lowbit(x);
    }
}

int sum(int l,int r) {
    int sum=0;

    while(r){
        sum+=tt[r];
        r-=lowbit(r);
    }

    l--;
    while(l){
        sum-=tt[l];
        l-=lowbit(l);
    }
    return sum;
}

void solve(){
    int n,m; cin>>n>>m;
    vector<int> v(n+1);
    map<int,int> mp;//下标->值
    map<int,vector<int>> idx; //值->新下标
    int cnt_z=0;
    for(int i=1; i<=n; i++){
        cin>>v[i];
        if(v[i]>0) cnt_z++;
        mp[i]=v[i];
    }

    sort(v.begin()+1,v.end());

    for(int i=1; i<=n; i++)
    {
        add(i,v[i]);
        idx[v[i]].push_back(i);
    }

    while(m--){
        int x,k; cin>>x>>k;
        int num=mp[x];
        mp[x]=k;//
        if(k<=0&&num>0) cnt_z--;
        else if(k>0&&num<=0) cnt_z++;

        int id=idx[num].back();
        idx[num].pop_back();//
        v.erase(v.begin()+id,v.begin()+id+1);
        auto idd=lower_bound(v.begin()+1,v.end(),k);
        v.insert(idd,k);
        int ww=idd-v.begin();
        idx[k].push_back(ww); //
        add(id,k-num);
        int l=1,r=n;
        while(l<r){
            int mid=(l+r)/2;
            if(sum(1,mid)>0) r=mid;
            else l=mid+1;
        }
        //        if(v[l]>0) l--;
        if(sum(1,l)<=0) l++;
        cout<<cnt_z-n+l<<endl;
    }
}
//x为下标,k为值
//找到这个下标(原数组)把它删掉
//二分这个值,把它插入
//树状数组求和二分

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    return 0;
}
/*
3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

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
Wrong Answer
time: 0ms
memory: 3584kb

input:

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

output:

1
2
0
0
1

result:

wrong answer 3rd numbers differ - expected: '1', found: '0'