比赛 USACO2026 JAN G&P2 评测结果 AAEEEEEEEEEEEEEEEEEEW
题目名称 COW Traversals 最终得分 8
用户昵称 梦那边的没好TM 运行时间 2.728 s
代码语言 C++ 内存使用 3.37 MiB
提交时间 2026-01-24 11:44:15
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define cpy(a,b) copy(begin(a),end(a),begin(b))
#define ld long double
#define dot(x) fixed<<setprecision(x)
#define foru(a,b,c) for(ll a=b;a<=c;a++)

ll n,m,a[105],type[105];
bool vis[105];

int main(){
    freopen("COW.in","r",stdin);
    freopen("COW.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    cin>>n;
    foru(i,1,n)cin>>a[i];
    cin>>m;
    while(m--){
        ll c;
        char ch;
        cin>>c>>ch;
        if(ch=='C')type[c]=1;
        else if(ch=='O')type[c]=2;
        else if(ch=='W')type[c]=3;
        else type[c]=0;
        ll cntc=0,cnto=0,cntw=0;
        foru(i,1,n){
            memset(vis,0,sizeof vis);
            ll cur=i;
            while(!vis[cur]){
                vis[cur]=1;
                if(type[cur]){
                    if(type[cur]==1)cntc++;
                    if(type[cur]==2)cnto++;
                    if(type[cur]==3)cntw++;
                    break;
                }
                cur=a[cur];
            }
        }
        cout<<cntc<<" "<<cnto<<" "<<cntw<<"\n";
    }
    return 0;
}