社区讨论

玄学做法 开O2居然有40分

P2146[NOI2015] 软件包管理器参与者 4已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mi7d17ah
此快照首次捕获于
2025/11/20 19:40
4 个月前
此快照最后确认于
2025/11/20 19:40
4 个月前
查看原帖
我可能做了道假题
CPP
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
    int n,q,x,ans,j,k;
	char ch;
	int *depon;
	bool *stat;
	vector<int> *depof;
	vector<int> list;
    scanf("%d",&n);
	depon=new int[n+1];
	stat=new bool[n+1];
	depof=new vector<int>[n+1];
	depon[0]=-1;
	stat[0]=false;
    for(int i=1;i<n;++i){
        scanf("%d",&x);
        depof[x].push_back(i);
        depon[i]=x;
        stat[i]=false;
    }
    scanf("%d",&q);
    for(int i=0;i<q;++i){
		ch=getchar();
		while((ch-'i')&&(ch-'u'))
			ch=getchar();
		if(ch=='u'){
			getchar();
			getchar();
		}
		for(int j=0;j<7;++j)
			getchar();
		scanf("%d",&x);
        ans=0;
        if(ch=='i'){
            j=x;
            while(j+1){
                ans+=!stat[j];
                stat[j]=true;
                j=depon[j];
            }
        }
        else if(ch=='u'){
            if(x==0){
				for(k=0;k<=n;++k){
					ans+=stat[k];
					stat[k]=false;
				}
            }
			else{
				list.push_back(x);
				while(!list.empty()){
					j=list.back();
					list.pop_back();
					ans+=!!stat[j];
					if(stat[j])
						list.insert(list.end(),depof[j].begin(),depof[j].end());
					stat[j]=false;
				}
            }
        }
		printf("%d\n",ans);
    }
	delete[] depon;
	delete[] stat;
	delete[] depof;
    return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...