QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795652#7787. Maximum RatingyouyouyouWA 2ms11992kbC++143.5kb2024-11-30 22:46:272024-11-30 22:46:27

Judging History

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

  • [2024-11-30 22:46:27]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11992kb
  • [2024-11-30 22:46:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
typedef struct{
    i64 score,num;
}dian;
i64 ans[800005][2],lisan[400005],chaxvn[200005][2],fusum=0,chushi[200005];
bool f=false;
dian a[400005];
int lc(int p){return p<<1;}
int rc(int p){return p<<1|1;}

void push_up(int p){
    ans[p][0]=(ans[lc(p)][0]+ans[rc(p)][0]);       //查询方式
    ans[p][1]=(ans[lc(p)][1]+ans[rc(p)][1]);       //查询方式
}
void build(i64 p,i64 l,i64 r)
{   
    if(l==r){ans[p][0]=a[l].num*a[l].score;ans[p][1]=a[l].num; return ;}      //建树,树里是什么
    i64 mid=(l+r)>>1;
    build(lc(p),l,mid);
    build(rc(p),mid+1,r);
    push_up(p);
}

void update(i64 nl,i64 nr,i64 l,i64 r,i64 p,i64 k)
{
    if(nl<=l&&r<=nr)        //更新值、懒标记
    {
        ans[p][1]+=k;            
        ans[p][0]+=k*a[l].score;
        return ;
    }
    i64 mid=(l+r)>>1;
    if(nl<=mid)update(nl,nr,l,mid,lc(p),k);
    if(nr>mid) update(nl,nr,mid+1,r,rc(p),k);
    push_up(p);
}
i64 query(i64 l,i64 r,i64 p,i64 val)
{
    if(l==r){
        if(ans[p][0]>val){
            i64 jige=val/a[l].score;
            if(jige*a[l].score!=val)jige++;
            return jige;
        }
        return -ans[p][1];
    }
	i64 mid=(l+r)>>1;
    i64 res=0;
	if(ans[p][0]>val){
        i64 zuo=query(l,mid,lc(p),val);
        if(zuo<=0){
            res+=(-zuo);
            i64 you= query(mid+1,r,rc(p),val-ans[lc(p)][0]);
            if(you<=0){
                res+=(-you);
                return -res;
            }else{
                res+=you;
                return res;
            }
        }else{
            return zuo;
        }
    }else{
        return -ans[p][1];
    }
    
}

void solve()
{
    i64 n,m,ls=0;
    cin>>n>>m;
    for(i64 i=1;i<=n;i++){
        cin>>chushi[i];
        if(chushi[i]>0){
            lisan[++ls]=chushi[i];
        }
    }
    for(i64 i=1;i<=m;i++){
        cin>>chaxvn[i][0]>>chaxvn[i][1];
        if(chaxvn[i][1]>0){
            lisan[++ls]=chaxvn[i][1];
        }
    }
    sort(lisan+1,lisan+1+ls);
    i64 tot=unique(lisan+1,lisan+1+ls)-lisan-1;
    map<i64,i64> mp;
    for(i64 i=1;i<=tot;i++){
        a[i].num=0;
        a[i].score=lisan[i];
        mp[lisan[i]]=i;
    }
    for(i64 i=1;i<=n;i++){
        if(chushi[i]<0)fusum+=(-chushi[i]);
        else if(chushi[i]>0){
            i64 weizhi=mp[chushi[i]];
            a[weizhi].num++;
        }
    }
    build(1,1,tot);

    for(i64 i=1;i<=m;i++){
        i64 qian=chushi[chaxvn[i][0]],hou=chaxvn[i][1];
        chushi[chaxvn[i][0]]=chaxvn[i][1];
        i64 wz1,wz2;
        if(qian<=0&&hou<=0){
            fusum+=(qian-hou);
        }else if(qian<=0){
            fusum-=(-qian);
            wz2=mp[hou];
            update(wz2,wz2,1,tot,1,1);
        }else if(hou<=0){
            fusum+=(-hou);
            wz1=mp[qian];
            update(wz1,wz1,1,tot,1,-1);
        }else{
            wz1=mp[qian],wz2=mp[hou];
            update(wz2,wz2,1,tot,1,1);
            update(wz1,wz1,1,tot,1,-1);
        }
        i64 jieguo=query(1,tot,1,fusum);
        if(jieguo<0){
            cout<<ans[1][1]+1<<'\n';
        }else if(jieguo==0){
            cout<<0<<'\n';
        }else{
            cout<<jieguo<<'\n';
        }
    }
}

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

    i64 T = 1;
    // cin >> T;
    while (T--)
        solve();

    return 0;
}

详细

Test #1:

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

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

input:

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

output:

1
2
1
2
2

result:

wrong answer 5th numbers differ - expected: '1', found: '2'