QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397575#5308. RPG Pro LeaguemarherWA 3ms13704kbC++142.0kb2024-04-24 13:31:102024-04-24 13:31:10

Judging History

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

  • [2024-04-24 13:31:10]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13704kb
  • [2024-04-24 13:31:10]
  • 提交

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];

struct node
{
    int w,x;

    friend bool operator<(node a,node b)
    {
        return a.w==b.w?a.x<b.x:a.w<b.w;
    }
};

multiset<node>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((node){c[i],i});
    cin>>m;
    while(m--)
    {
        int x,w;cin>>x>>w;
        S[p[x]][g[x]].erase((node){c[x],x});ans-=g[x]*c[x];c[x]=w;
        S[p[x]][g[x]].insert((node){c[x],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()).x;
            else u=S[i][1].empty()?0:(*prev(S[i][1].end())).x;
            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((node){c[x],x});S[p[v]][g[v]].erase((node){c[v],v});
            add(x),add(v);
            S[p[x]][g[x]].insert((node){c[x],x});S[p[v]][g[v]].insert((node){c[v],v});
        }
        cout<<ans<<'\n';
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 13704kb

input:

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

output:


result:

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