题解:P13912 [CSPro 26] 角色授权

· · 题解

请叫我肝帝好吧

#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;
string rn[505];
int rv[505];
string ro[505][405];
int rty[505];
string rt[505][405];
int rnn[505];
string rna[505][405];
int roh[505];
int rth[505];
pair<string,int> sb[200005];
int sc;
int cd[505];
string gp[405];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=1; i<=n; i++)
        {
            cin>>rn[i];
            cin>>rv[i];
            roh[i]=0;
            for(int j=1; j<=rv[i]; j++)
                {
                    cin>>ro[i][j];
                    if(ro[i][j]=="*")
                        {
                            roh[i]=1;
                        }
                }
            sort(ro[i]+1,ro[i]+rv[i]+1);
            cin>>rty[i];
            rth[i]=0;
            for(int j=1; j<=rty[i]; j++)
                {
                    cin>>rt[i][j];
                    if(rt[i][j]=="*")
                        {
                            rth[i]=1;
                        }
                }
            sort(rt[i]+1,rt[i]+rty[i]+1);
            cin>>rnn[i];
            for(int j=1; j<=rnn[i]; j++)
                {
                    cin>>rna[i][j];
                }
            sort(rna[i]+1,rna[i]+rnn[i]+1);
        }
    sc=0;
    for(int i=1; i<=m; i++)
        {
            string r2;
            cin>>r2;
            int rid=0;
            for(int j=1; j<=n; j++)
                {
                    if(rn[j]==r2)
                        {
                            rid=j;
                            break;
                        }
                }
            int ns;
            cin>>ns;
            for(int j=1; j<=ns; j++)
                {
                    string typ,nm;
                    cin>>typ>>nm;
                    sc++;
                    sb[sc]=make_pair(typ+nm,rid);
                }
        }
    sort(sb+1,sb+sc+1);
    for(int qq=1; qq<=q; qq++)
        {
            string un;
            cin>>un;
            int ng;
            cin>>ng;
            for(int i=1; i<=ng; i++)
                {
                    cin>>gp[i];
                }
            string op,tp,rm;
            cin>>op>>tp>>rm;
            for(int i=1; i<=n; i++)
                {
                    cd[i]=0;
                }
            string key="u"+un;
            pair<string,int>* lo=lower_bound(sb+1,sb+sc+1,make_pair(key,0));
            pair<string,int>* hi=lower_bound(sb+1,sb+sc+1,make_pair(key,1000));
            for(pair<string,int>* it=lo; it!=hi; it++)
                {
                    cd[it->second]=1;
                }
            for(int i=1; i<=ng; i++)
                {
                    key="g"+gp[i];
                    lo=lower_bound(sb+1,sb+sc+1,make_pair(key,0));
                    hi=lower_bound(sb+1,sb+sc+1,make_pair(key,1000));
                    for(pair<string,int>* it=lo; it!=hi; it++)
                        {
                            cd[it->second]=1;
                        }
                }
            int ok=0;
            for(int i=1; i<=n; i++)
                {
                    if(cd[i]==0)
                        {
                            continue;
                        }
                    int o1=0;
                    if(roh[i])
                        {
                            o1=1;
                        }
                    else
                        {
                            if(binary_search(ro[i]+1,ro[i]+rv[i]+1,op))
                                {
                                    o1=1;
                                }
                        }
                    if(o1==0)
                        {
                            continue;
                        }
                    int t1=0;
                    if(rth[i])
                        {
                            t1=1;
                        }
                    else
                        {
                            if(binary_search(rt[i]+1,rt[i]+rty[i]+1,tp))
                                {
                                    t1=1;
                                }
                        }
                    if(t1==0)
                        {
                            continue;
                        }
                    int n1=1;
                    if(rnn[i]>0)
                        {
                            n1=0;
                            if(binary_search(rna[i]+1,rna[i]+rnn[i]+1,rm))
                                {
                                    n1=1;
                                }
                        }
                    if(n1)
                        {
                            ok=1;
                            break;
                        }
                }
            cout<<ok<<endl;
        }
    return 0;
}