优先队列求助
查看原帖
优先队列求助
696996
restart_to_revive楼主2023/7/17 18:15
#include <bits/stdc++.h>
using namespace std;
int inp;
char a[500005];
int b[500005],c[500005];
int ship[30005];
struct abc{
	queue <int>q;
};
struct abc aaa[30005];
int main(){
	cin>>inp;
	for(int i=1;i<30001;i++){
		ship[i]=i+1;
		aaa[ship[b[i]]].q.push(b[i]);
	}
	for(int i=0;i<inp;i++){
		cin>>a[i]>>b[i]>>c[i];
		for(int j=1;j<30001;j++){
			aaa[ship[j]].q.push(j);
		}
		if(a[i]=='C'){
			if(ship[b[i]]==ship[c[i]]){
				cout<<aaa[ship[b[i]]].q.size()-1<<endl;
			}
			else{
				cout<<-1<<endl;
			}
		}
		else{
			for(int i=0;i<aaa[ship[b[i]]].q.size();i++){
				aaa[ship[c[i]]].q.push(aaa[ship[b[i]]].q.front());
				aaa[ship[b[i]]].q.pop();
				ship[b[i]]=ship[c[i]];
			}
		}
	}
	return 0;
}

优先队列求助 0分

2023/7/17 18:15
加载中...