QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#416501 | #5308. RPG Pro League | grass8cow | RE | 0ms | 3784kb | C++17 | 2.1kb | 2024-05-21 21:51:04 | 2024-05-21 21:51:06 |
Judging History
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];
bool vis[100100];
ll sum;
int pp[16],zd,a[100100],so[101000];
const int I=1e9+7;
bool tryout(){
int st=0;
for(int s=1;s<16;s++){
int zx=0;
for(int i=0;i<16;i++)if(i&s)zx+=L[i].size();
if(zx==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].end())).fi;
if(mx<oo)mx=oo,s2=i;
}
if(mx==-1)return 0;st=s2;
pi is=*(--L[st].end());
sum-=mx,L[st].erase(is),R[st].insert(is),vis[is.se]=0;
return 1;
}
void tryin(){
int st=15;
for(int s=1;s<16;s++){
int zx=0;
for(int i=0;i<16;i++)if(i&s)zx+=L[i].size();
if(zx<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;
}
st=s2;
pi is=*R[st].begin();
sum+=mi,R[st].erase(is),L[st].insert(is),vis[is.se]=1;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;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;
}
L[st].insert({a[i],i}),sum+=a[i],vis[i]=1;
so[i]=st;
}
zd=n+1;
for(int s=1;s<16;s++){
pp[s]=pp[s>>1]+(s&1);int zx=0;
for(int i=0;i<16;i++)if(i&s)zx+=L[i].size();
zd=min(zd,zx/pp[s]);
}
while(tryout());
int q;scanf("%d",&q);
for(int i=1,x,z;i<=q;i++){
scanf("%d%d",&x,&z);
if(vis[x]){
sum-=a[x],
vis[x]=0,L[so[x]].erase({a[x],x}),a[x]=z,R[so[x]].insert({a[x],x});
tryin();
}
else{
vis[x]=1,R[so[x]].insert({a[x],x}),a[x]=z,L[so[x]].insert({a[x],x}),
sum+=a[x];
tryout();
}
printf("%lld\n",sum);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
input:
5 BS 3 D 3 B 2 D 4 D 5 2 5 2 1 5
output:
10 12
result:
ok 2 number(s): "10 12"
Test #2:
score: -100
Runtime Error
input:
100000 B 727564174 S 231637747 D 246625257 S 975124756 D 844292741 S 809641006 B 396062588 B 883224128 B 311130283 S 434433581 S 509817048 S 993501344 S 508399542 B 279564062 D 950946642 D 819528264 D 412285620 B 968540732 S 953428318 D 902181790 S 172330493 D 725075 B 135580649 D 714478555 B 466916...
output:
40721766963064 40720937650054 40721120372880 40720722768213 40721029809776 40720546822562 40719680807733 40720084910620 40720153432078 40720873952927 40721146683113 40721696875436 40722235723316 40722133896063 40723047443192 40723419347010 40722633976087 40722282806304 40722071958869 40721278798949 ...