使用stl的list 后三个tle,求大佬优化!!
查看原帖
使用stl的list 后三个tle,求大佬优化!!
568637
liang302楼主2021/11/27 09:56
#include <bits/stdc++.h>
using namespace std;


int a[100005];
list<int >l;
int main (void)
{
int n,m,k,p;
cin>>n;l.push_back(1);
for(int i=2;i<=n;i++) 
{	cin>>k>>p;


	if (p) l.insert(++find(l.begin(), l.end(), k) , i); //在右边插入
        else l.insert(find(l.begin(), l.end(), k), i ); //在左边插入
	
	
	
}int x;
cin>>m;
for(int i=1;i<=m;i++) 	
{	
	cin>>x;
	a[x]=1;
	
	}
	

for(list<int > ::iterator it=l.begin();it!=l.end();it++){
	if(!a[*it]) cout<<*it<<" ";
}//输出 
}
2021/11/27 09:56
加载中...