QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99034#5504. Flower Gardenice_cupWA 3ms21856kbC++143.9kb2023-04-21 09:07:492023-04-21 09:07:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 09:07:50]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:21856kb
  • [2023-04-21 09:07:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int z,n,Q,head[5001000],to[10001000],nxt[10001000],v[5001000],cnt,tot;
int head1[5001000],to1[10001000],nxt1[10001000],cnt1;
int tr1[100100<<2],tr2[100100<<2];
int dfn[5001000],low[5001000],s[5001000],t,be[5001000],val[5001000],bel,tim,vis[5001000];
int c[5000100];
int in[5000100];
void add(int u,int e){
	nxt[++cnt]=head[u];
	to[cnt]=e;
	head[u]=cnt;
}
void addd(int u,int e){
	nxt1[++cnt1]=head1[u];
	to1[cnt1]=e;
	head1[u]=cnt1;
}
#define ls p<<1
#define rs p<<1|1
#define MID int mid=(l+r)>>1
//1向上连边 2向下连边
void build1(int l,int r,int p){
	if(l==r){
		tr1[p]=l;
		v[tr1[p]]=1;
		return;
	}
	tr1[p]=++tot;
	MID;
	build1(l,mid,ls),build1(mid+1,r,rs);
	add(tr1[ls],tr1[p]),add(tr1[rs],tr1[p]);
}
void build2(int l,int r,int p){
	if(l==r){
		tr2[p]=l;
		v[tr2[p]]=1;
		return;
	}
	tr2[p]=++tot;
	MID;
	build2(l,mid,ls),build2(mid+1,r,rs);
	add(tr2[p],tr2[ls]),add(tr2[p],tr2[rs]);
}
void link1(int l,int r,int lin,int rin,int p,int point){

	if(l==lin&&r==rin){
		add(tr1[p],point);
		return;
	}
	MID;
	if(rin<=mid)link1(l,mid,lin,rin,ls,point);
	else if(lin>mid)link1(mid+1,r,lin,rin,rs,point);
	else link1(l,mid,lin,mid,ls,point),link1(mid+1,r,mid+1,rin,rs,point);
}
void link2(int l,int r,int lin,int rin,int p,int point){
	// cout<<l<<' '<<r<<' '<<lin<<' '<<rin<<endl;
	if(l==lin&&r==rin){
		add(point,tr2[p]);
		return;
	}
	MID;
	if(rin<=mid)link2(l,mid,lin,rin,ls,point);
	else if(lin>mid)link2(mid+1,r,lin,rin,rs,point);
	else link2(l,mid,lin,mid,ls,point),link2(mid+1,r,mid+1,rin,rs,point);
}
void tarjan(int u){ 
	low[u]=dfn[u]=++tim;
	s[++t]=u;
	for(int i=head[u];i;i=nxt[i]){
		if(!dfn[to[i]]){
			tarjan(to[i]);//if(u==3)cout<<to[i]<<' '<<low[to[i]]<<endl;
			low[u]=min(low[u],low[to[i]]);
		}
		else if(!vis[to[i]])low[u]=min(low[u],dfn[to[i]]);
	}
	if(low[u]==dfn[u]){
		bel++;
		// cout<<"oh "<<u<<endl;
		while(s[t+1]!=u){
			// cout<<s[t]<<' ';
			be[s[t]]=bel;
			vis[s[t]]=1;
			val[bel]+=v[s[t]];
			t--;
		}
		// cout<<endl;
	}
}
queue<int>q;
int bfs1(int s){
	int ans=0;
	q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();
		c[u]=1;
		ans+=val[u];
		for(int i=head1[u];i;i=nxt1[i]){
			q.push(to1[i]);
		}
	}
	return ans;
}
void bfs(){
	int ans=0;
	for(int i=1;i<=bel;i++){
		if(!in[i])q.push(i);
	}
	while(!q.empty()){
		int u=q.front();q.pop();
		// cout<<u<<' ';
		c[u]=1;
		ans+=val[u];
		// cout<<ans<<endl;
		if(ans>=n&&ans<=2*n)return;
		for(int i=head1[u];i;i=nxt1[i]){
			q.push(to1[i]);
		}
	}
}
void solve(){
	cin>>n>>Q;
	tot=3*n;
	build1(1,3*n,1);
	build2(1,3*n,1);
	int a1,a2,b1,b2;
	while(Q--){
		scanf("%d%d%d%d",&a1,&a2,&b1,&b2);
		int ne=++tot;
		link1(1,3*n,a1,a2,1,ne);
		link2(1,3*n,b1,b2,1,ne);

	}
	// for(int u=1;u<=tot;u++){
	// 	cout<<"p "<<u<<endl;
	// 	for(int i=head[u];i;i=nxt[i]){
	// 		cout<<to[i]<<' ';
	// 	}
	//  	cout<<endl;
	// }
	for(int i=1;i<=tot;i++){
		if(!dfn[i]){
			tarjan(i);
		}
	}
	for(int u=1;u<=tot;u++){
		for(int i=head[u];i;i=nxt[i]){
			if(be[u]!=be[to[i]]){
				addd(be[u],be[to[i]]);
				// cout<<be[u]<<' '<<be[to[i]]<<endl;
				in[be[to[i]]]++;
				// cout<<to[i]<<' ';
			}
		}
	}
	int f=0;
	for(int i=1;i<=bel;i++){
		if(val[i]>n){
			int re=bfs1(i);
			if(re>=n&&re<=2*n){
				f=1;
				cout<<"TAK\n";
				for(int i=1;i<=3*n;i++){
					if(c[be[i]]==1)cout<<'F';
					else cout<<'R';
				}
				cout<<'\n';
				break;
			}
			else{
				f=1;
				cout<<"NIE\n";
			}
		}
	}
	if(!f){
		bfs();
		cout<<"TAK\n";
		for(int i=1;i<=3*n;i++){
			if(c[be[i]]==0)cout<<'F';
			else cout<<'R';
		}
		cout<<'\n';
	}
	cnt=cnt1=t=0;
	for(int i=1;i<=tot;i++){
		head[i]=head1[i]=0;
		dfn[i]=low[i]=vis[i]=0;
	}
	tot=0;
	for(int i=1;i<=bel;i++){
		be[i]=val[i]=c[i]=in[i]=0;
	}
	bel=0;
}
int main(){
	cin>>z;
	while(z--)solve();
}
/*
1
1 3
1 1 2 2
1 2 3 3
1 1 3 3
*/

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 21856kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
FFR
NIE

result:

wrong answer odpowiedz nie spelnia wymogow!