QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#704995#7787. Maximum Ratingqikala7777WA 1ms7804kbC++233.0kb2024-11-02 21:48:482024-11-02 21:48:48

Judging History

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

  • [2024-11-02 21:48:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7804kb
  • [2024-11-02 21:48:48]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=4e5+7,inf=0x3f3f3f3f;const LL Linf=0x3f3f3f3f3f3f3f3fLL;
LL qsm(LL a,LL b,LL p){LL res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
LL lowbit(LL x){return x&-x;}
#define int LL
int n,q,ll;
int a[N];
LL sms;
map<int,int>mp;
struct{
    int op,v;
}cz[N];
vector<int>p;
int get(int x){
    return lower_bound(p.begin(),p.end(),x)-p.begin()+1;
}
struct seg{
    int l,r;
    LL v;
    LL cnt;
}tr[N<<2];
void pushup(int u){
    tr[u].v=tr[u<<1].v+tr[u<<1|1].v;
    tr[u].cnt=tr[u<<1].cnt+tr[u<<1|1].cnt;
}
void build(int u,int x,int y){
    tr[u]={x,y,0,0};	
    if(x>=y){
        tr[u].cnt=mp[x];
        tr[u].v=tr[u].cnt*p[x-1];
        return;					
    }else{
        int mid=x+y>>1;
        build(u<<1,x,mid),build(u<<1|1,mid+1,y);
        pushup(u);
        return;
    }
}
void change(int u,int op,int qt){
    if(tr[u].l>=tr[u].r){
        if(tr[u].l!=op)return;
        tr[u].cnt+=qt;
        tr[u].v=tr[u].cnt*p[tr[u].l-1];
        return;
    }
    int mid=tr[u].l+tr[u].r>>1;
    if(op<=mid){
        change(u<<1,op,qt);
    }else{
        change(u<<1|1,op,qt);
    }
    pushup(u);
}
LL query(int u,LL sms){
    if(tr[u].l==tr[u].r){
        if(tr[u].v>sms){
            return sms/p[tr[u].l-1];
        }else{
            return tr[u].cnt;
        }
    }
    if(tr[u<<1].v>=sms){
        return query(u<<1,sms);
    }else{
        return tr[u<<1].cnt+query(u<<1|1,sms-tr[u<<1].v);
    }
}


void solve(){
    cin>>n>>q;
    int ks=0;//正数的个数
    sms=0;//负数和
    p.push_back(0);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>0){
            ks++;
            p.push_back(a[i]);
        }else if(a[i]<0){
            sms+=-a[i];
        }
    }
    for(int i=1;i<=q;i++){
        cin>>cz[i].op>>cz[i].v;
        if(cz[i].v>0)p.push_back(cz[i].v);
    }
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(),p.end()),p.end());
    ll=p.size();
    for(int i=1;i<=n;i++){
        if(a[i]>0){
            mp[get(a[i])]++;
        }
    }
    build(1,1,ll);
    for(int i=1;i<=q;i++){
        int x=cz[i].op,v=cz[i].v;
        int t=a[x];
        if(v<0){
            if(t<0)sms-=-t;
            else if(t>0){
                --ks;
                change(1,get(t),-1);
            }
            sms+=-v;
        }else if(v>0){
            if(t<0)sms-=-t;
            else if(t>0){
                --ks;
                change(1,get(t),-1);
            }
            ks++;
            change(1,get(v),1);
        }
        LL kmax=ks;
        a[x]=v;
        LL kmin=ks-query(1,sms);
        //cout<<query(1,sms)<<endl;
        cout<<kmax-kmin+1<<endl;
    }
}
signed main(){
   IOS
   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: 1ms
memory: 7768kb

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 7804kb

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:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
301
598
1000
1000
810
1000
942
355
1000
1000
644
764
1000
1000
1000
871
910
791
742
1000
401
1000
1000
924
913
725
645
1000
723
575
521
617
413
68...

result:

wrong answer 40th numbers differ - expected: '1', found: '301'