QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416534#5308. RPG Pro Leaguegrass8cowRE 0ms0kbC++172.2kb2024-05-21 22:24:432024-05-21 22:24:44

Judging History

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

  • [2024-05-21 22:24:44]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-21 22:24:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
#define ll long long
#define pi pair<int,int>
#define fi first
#define se second
set<pi>L[16],R[16];
char S[3];
int tx[16];
bool vis[100100];
ll sum;
int pp[16],zd,a[100100],so[101000];
const int I=1e9+7;
void ao(int x,int z){for(int i=0;i<16;i++)if(x&i)tx[i]+=z;}
void tryout(){
    int st=0;
    for(int s=1;s<16;s++)
        if(tx[s]==zd*pp[s])st|=s;
    int mx=-1,s2=-1;
    for(int i=0;i<16;i++)if(!(i&st)&&!L[i].empty()){
        int oo=(*L[i].rbegin()).fi;
        if(mx<oo)mx=oo,s2=i;
    }
    assert(s2!=-1);
    st=s2;pi is=*L[st].rbegin();
    ao(st,-1);
    sum-=mx,L[st].erase(is),R[st].insert(is),vis[is.se]=0;
}
void tryin(){
    int st=15;
    for(int s=1;s<16;s++)if(tx[s]<zd*pp[s])st&=s;
    int mi=I,s2=-1;
    for(int i=0;i<16;i++)if((i&st)&&!R[i].empty()){
        int oo=(*R[i].begin()).fi;
        if(mi>oo)mi=oo,s2=i;
    }
    assert(s2!=-1);
    st=s2;
    pi is=*R[st].begin();
    ao(st,1);
    sum+=mi,R[st].erase(is),L[st].insert(is),vis[is.se]=1;
}
int gx[101000];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        gx[i]=i;
        scanf("%s%d",S,&a[i]);int O=strlen(S),st=0;
        for(int j=0;j<O;j++){
            if(S[j]=='D')st|=9;
            if(S[j]=='S')st|=10;
            if(S[j]=='B')st|=4;
        }
        ao(st,1),so[i]=st;
    }
    zd=n+1;
    for(int s=1;s<16;s++)
        pp[s]=pp[s>>1]+(s&1),zd=min(zd,tx[s]/pp[s]);
    sort(gx+1,gx+n+1,[&](int x,int y){return a[x]<a[y];});
    for(int i=n;i;i--){
        int u=gx[i];
        int st=0;for(int s=1;s<16;s++)if(tx[s]==zd*pp[s])st|=s;
        if(st&so[u])L[so[u]].insert({a[u],u}),sum+=a[u],vis[u]=1;
        else R[so[u]].insert({a[u],u}),ao(so[u],-1);
    }
    int q;scanf("%d",&q);
    for(int i=1,x,z;i<=q;i++){
        scanf("%d%d",&x,&z);
        if(vis[x]){
            vis[x]=0,sum-=a[x],ao(so[x],-1);
            L[so[x]].erase({a[x],x}),a[x]=z;
            tryin();if(!vis[x])R[so[x]].insert({a[x],x});
        }
        else{
            vis[x]=1,ao(so[x],1);
            R[so[x]].erase({a[x],x}),a[x]=z,L[so[x]].insert({a[x],x}),
            sum+=a[x];
            tryout();
        }
        printf("%lld\n",sum);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

5
BS 3
D 3
B 2
D 4
D 5
2
5 2
1 5

output:


result: