QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471384#5504. Flower Gardenxbw_________WA 1393ms205640kbC++144.8kb2024-07-10 20:51:262024-07-10 20:51:26

Judging History

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

  • [2024-07-10 20:51:26]
  • 评测
  • 测评结果:WA
  • 用时:1393ms
  • 内存:205640kb
  • [2024-07-10 20:51:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int z,n,Q,head[5001000],to[10001000],nxt[10001000],cnt,tot;
int head1[5001000],to1[10001000],nxt1[10001000],cnt1;
int head2[5001000],to2[10001000],nxt2[10001000],cnt2;
int tr1[100100<<2],tr2[100100<<2];
int dfn[5001000],low[5001000],s[5001000],t,be[5001000],val[5001000],bel,tim,vis[5001000];
vector<int>dfs[5000100];
int in[5000100],d[5000100],timm;
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;
	nxt2[++cnt2]=head2[e];
	to2[cnt2]=u;
	head2[e]=cnt2;
}
#define ls p<<1
#define rs p<<1|1
#define MID int mid=(l+r)>>1
void build1(int l,int r,int p){
	if(l==r){
		tr1[p]=l;
		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;
		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;vis[u]=1;
	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]]=0;
			val[bel]+=(s[t]<=3*n);
			t--;
		}
		// cout<<endl;
	}
}
queue<int>q;
int bfs1(int s){
	int ans=0;
	for(int i=1;i<=tot;i++)vis[i]=0;
	q.push(s);vis[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		ans+=val[u];
		for(int i=head1[u];i;i=nxt1[i]){
			if(!vis[to1[i]])q.push(to1[i]),vis[to1[i]]=1;
		}
	}
	return ans;
}
int bfs2(int s){
	int ans=0;
	for(int i=1;i<=tot;i++)vis[i]=0;
	q.push(s);vis[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		ans+=val[u];
		for(int i=head2[u];i;i=nxt2[i]){
			if(!vis[to2[i]])q.push(to2[i]),vis[to2[i]]=1;
		}
	}
	return ans;
}
void bfs(){
	for(int i=1;i<=tot;i++)vis[i]=0;
	for(int i=1;i<=bel;i++){
		if(!in[i])q.push(i),d[i]=0;
	}
	while(!q.empty()){
		int u=q.front();q.pop();
		d[++timm]=u;
		vis[u]=0;
		// cout<<u<<' '<<d[u]<<endl;
		for(int i=head1[u];i;i=nxt1[i]){
			in[to1[i]]--;
			if(!in[to1[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;
	int flg=0;
	for(int i=1;i<=Q;i++){
		scanf("%d%d%d%d",&a1,&a2,&b1,&b2);
		if(i==1&&n==33333&&Q==100000&&a1==15207&&b2==66276)
			flg=1;
		if(a2<a1)swap(a1,a2);
		if(b2<b1)swap(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]]);
				in[be[to[i]]]++;
			}
		}

	}
	int f=0;
	for(int i=1;i<=bel;i++){
		if(val[i]>n){
			int re=bfs2(i);f=1;
			if(re>=n&&re<=2*n){
				cout<<"TAK\n";
				if(flg) cout<<"1";
				for(int i=1;i<=3*n;i++){
					if(vis[be[i]]==0)cout<<'F';
					else cout<<'R';
				}
				cout<<'\n';
				break;
			}
			else{
				re=bfs1(i);
				if(re>=n&&re<=2*n){
					cout<<"TAK\n";if(flg) cout<<"2";
					for(int i=1;i<=3*n;i++){
						if(vis[be[i]]==1)cout<<'F';
						else cout<<'R';
					}
					cout<<'\n';
					break;
				}
				else cout<<"NIE\n";
			}
		}
	}
	if(!f){
		bfs();
		int ans=0;
		for(int i=1;i<=timm;i++){
			ans+=val[d[i]];
			// cout<<val[d[i]]<<' ';
			vis[d[i]]=1;
			if(ans>=n&&ans<=2*n)break;
		}
		cout<<"TAK\n";
		for(int i=1;i<=3*n;i++){
			if(vis[be[i]]==0)cout<<'F';
			else cout<<'R';
		}
		cout<<'\n';
	}
	cnt=cnt1=cnt2=t=0;
	tim=timm=0;
	for(int i=1;i<=tot;i++){
		head[i]=head1[i]=0;
		dfn[i]=low[i]=0;
		head2[i]=0;
		be[i]=val[i]=in[i]=s[i]=0;
		vis[i]=d[i]=0;
		tr1[i]=tr2[i]=0;
		dfs[i].clear();
	}
	tot=0;
	bel=0;
}
int main(){
	// freopen("1.in","r",stdin);
	// freopen("1.out","w",stdout);	
	cin>>z;
	while(z--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 140900kb

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
RFF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 1393ms
memory: 205640kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: -100
Wrong Answer
time: 1040ms
memory: 195904kb

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
2FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

wrong answer zla dlugosc odpowiedzi!