QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703479#7787. Maximum Ratingqikala7777WA 1ms7756kbC++233.3kb2024-11-02 17:51:442024-11-02 17:51:45

Judging History

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

  • [2024-11-02 17:51:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7756kb
  • [2024-11-02 17:51:44]
  • 提交

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};	
    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){
        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,int x,int y){
    if(tr[u].l>=x&&tr[u].r<=y){
        return tr[u].v;
    }
    int mid=tr[u].l+tr[u].r>>1;
    LL res=0;
    if(x<=mid)res+=query(u<<1,x,y);
    if(y>mid)res+=query(u<<1|1,x,y);
    return res;
}
LL query1(int u,int x,int y){
    if(tr[u].l>=x&&tr[u].r<=y){
        return tr[u].cnt;
    }
    int mid=tr[u].l+tr[u].r>>1;
    LL res=0;
    if(x<=mid)res+=query1(u<<1,x,y);
    if(y>mid)res+=query1(u<<1|1,x,y);
    return res;
}
int qus(){
    int l=1,r=ll,ans=-1;
    while(l<=r){
        int mid=l+r>>1;
        if(query(1,1,mid)>sms){
            r=mid-1;
            ans=mid;
        }else{
            l=mid+1;
        }
    }
    if(ans==-1)return 0;
    return query1(1,ans,ll);
}
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=qus();
        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: 0ms
memory: 7672kb

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

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

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
1000
1000
1
1000
1
1
1000
1000
1
1
1000
1000
1000
1
1
1
1
1000
1
1000
1000
1
1
1
1
1000
1
1
1
1
1
1
1
1
1
1
1000
1
1
1
1
1
1
1000
1000
1
1
1
1
1000
1
1
1
1
1000
1
1
1
1
1
1
1
1
1
1
1000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1000...

result:

wrong answer 1st numbers differ - expected: '946', found: '1'