pbds RE求助
查看原帖
pbds RE求助
226839
Jorylee楼主2022/2/26 13:51

错误信息是 Runtime Error. Received signal 6: Aborted / IOT trap.

代码如下,希望能有高人指点

#include<bits/stdc++.h>
#define ffor(i,l,r) for(int i=(l),i##_end=(r);i<=i##_end;++i)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef std::pair<int,int> Key;
__gnu_pbds::tree<std::pair<int, int>, __gnu_pbds::null_type,
           std::less<std::pair<int, int> >, __gnu_pbds::rb_tree_tag,
           __gnu_pbds::tree_order_statistics_node_update>
           T[100010];
using namespace std;
int n,m,q;
int p[100010];
int fa[100010];
int getFa(int x) {
	if(fa[x]==x) return x;
	else return fa[x] = getFa(fa[x]);
}
int main() {
	scanf("%d%d",&n,&m);
	ffor(i,1,n) scanf("%d",&p[i]);
	ffor(i,1,n) fa[i] = i;
	ffor(i,1,n) {
		T[i].insert(make_pair(p[i],i));
	}
	while(m--) {
		int x,y;
		scanf("%d%d",&x,&y);
		x = getFa(x);
		y = getFa(y);
		if(x==y) continue;
		if(T[x].size()>T[y].size()) {
			fa[y] = x;
			T[x].join(T[y]);
		} else {
			fa[x] = y;
			T[y].join(T[x]);
		}
	}
	scanf("%d",&q);
	while(q--) {
		char op;
		int x,y;
		scanf(" %c%d%d",&op,&x,&y);
		if(op=='Q') {
			x = getFa(x);
			if(T[x].size()<y) puts("-1");
			else printf("%d\n",T[x].find_by_order(y-1)->second);
		} else {
			x = getFa(x);
			y = getFa(y);
			if(x==y) continue;
			if(T[x].size()>T[y].size()) {
				fa[y] = x;
				T[x].join(T[y]);
			} else {
				fa[x] = y;
				T[y].join(T[x]);
			}
		}
	}
	return 0;
}

2022/2/26 13:51
加载中...