QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770204#7787. Maximum Ratingjiangzhihui#WA 2ms12000kbC++142.1kb2024-11-21 21:07:032024-11-21 21:07:03

Judging History

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

  • [2024-11-21 21:07:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12000kb
  • [2024-11-21 21:07:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e5+10;
struct treearr{
    ll c[N];
    int lowbit(int x){
        return x&(-x);
    }
    void add(int p,int v){
        while(p<N){
            c[p]+=v;
            p+=lowbit(p);
        }
    }
    ll query(int p){
        ll res=0;
        while(p){
            res+=c[p];
            p-=lowbit(p);
        }
        return res;
    }
};
struct query{
    int pos,v;
};
int a[N],n,q,b[N],len;
query qs[N];
void init(){
    map<int,int> mp;
    sort(b+1,b+1+len);
    len=unique(b+1,b+1+len)-b-1;
    for(int i=1;i<=len;i++){
        mp[b[i]]=i;
    }
    for(int i=1;i<=n;i++){
        if(a[i]>0){
            a[i]=mp[a[i]];
        }
    }
    for(int i=1;i<=q;i++){
        if(qs[i].v>0){
            qs[i].v=mp[qs[i].v];
        }
    }
}
treearr t1,t2;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>0){
            b[++len]=a[i];
        }
    }
    for(int i=1;i<=q;i++){
        cin>>qs[i].pos>>qs[i].v;
        if(qs[i].v>0){
            b[++len]=qs[i].v;
        }
    }
    init();
    ll f_sum=0;
    for(int i=1;i<=n;i++){
        if(a[i]>0){
            t1.add(a[i],1);
            t2.add(a[i],b[a[i]]);
        }else{
            f_sum+=a[i];
        }
    }
    for(int i=1;i<=q;i++){
        int pos=qs[i].pos;
        int v=qs[i].v;
        if(a[pos]>0){
            t1.add(a[pos],-1);
            t2.add(a[pos],-b[a[pos]]);
        }else{
            f_sum-=a[pos];
        }
        a[pos]=v;
        if(a[pos]>0){
            t1.add(a[pos],1);
            t2.add(a[pos],b[a[pos]]);
        }else{
            f_sum+=a[pos];
        }
        int mx=t1.query(len);
        int l=1,r=len;
        while(l<=r){
            int mid=(l+r)>>1;
            if(t2.query(mid)+f_sum>0){
                r=mid-1;
            }else{
                l=mid+1;
            }
        }
        int mn=t1.query(len)-t1.query(l-1);
        cout<<mx-mn+1<<'\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9756kb

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: 11752kb

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: 2ms
memory: 11780kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7548kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 12000kb

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'