QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397537#5308. RPG Pro LeaguemarherWA 62ms18644kbC++141.9kb2024-04-24 11:56:252024-04-24 11:56:25

Judging History

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

  • [2024-04-24 11:56:25]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:18644kb
  • [2024-04-24 11:56:25]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+50,M=10000,inf=1e9+7;

int n,c[N],k,b[N],p[N],m,d[N],f[18],g[N];
ll ans;
map<string,int>mp;
string s[N];

multiset<int>S[20][2];

bool cmp(int a,int b)
{
    return c[a]>c[b];
}

void add(int x)
{
    if(g[x])
    {
        ans-=c[x];
        for(int i=1;i<=15;i++)if(i&p[x])f[i]--;
    }
    g[x]^=1;
    if(g[x])
    {
        ans+=c[x];
        for(int i=1;i<=15;i++)if(i&p[x])f[i]++;
    }
}

int sol()
{
    int ans=inf;
    for(int i=1;i<=15;i++)ans=min(ans,f[i]/__popcount(i));
    return ans;
}

main()
{
    // freopen("in.txt","r",stdin);
    mp["B"]=1;mp["D"]=2+8;mp["S"]=4+8;mp["BD"]=3+8;mp["BS"]=5+8;mp["DS"]=6+8;mp["BDS"]=7+8;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>s[i]>>c[i],sort(s[i].begin(),s[i].end()),p[i]=mp[s[i]],d[i]=i;
    sort(d+1,d+1+n,cmp);
    for(int i=1;i<=n;i++)add(i);k=sol();
    for(int i=1;i<=n;i++)
    {
        add(d[i]);
        if(sol()<k)add(d[i]);
    }
    for(int i=1;i<=n;i++)S[p[i]][g[i]].insert(c[i]);
    if(n>10)return 0;
    cin>>m;
    while(m--)
    {
        int x,w;cin>>x>>w;
        S[p[x]][g[x]].erase(c[x]);ans-=g[x]*c[x];c[x]=w;
        S[p[x]][g[x]].insert(c[x]);ans+=g[x]*c[x];
        int v=0;ll val=ans;
        for(int i=1;i<=15;i++)
        {
            int u=0;
            if(g[x])u=S[i][0].empty()?0:*S[i][0].begin();
            else u=S[i][1].empty()?0:*prev(S[i][1].end());
            if(u)
            {
                add(x);add(u);
                if(sol()==k&&ans<val)val=ans,v=u;
                add(x);add(u);
            }
        }
        if(v)
        {
            S[p[x]][g[x]].erase(c[x]);S[p[v]][g[v]].erase(c[v]);
            add(x),add(v);
            S[p[x]][g[x]].insert(c[x]);S[p[v]][g[v]].insert(c[v]);
        }
        cout<<ans<<'\n';
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 12176kb

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
Wrong Answer
time: 62ms
memory: 18644kb

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:


result:

wrong answer Answer contains longer sequence [length = 100000], but output contains 0 elements