QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471386#5504. Flower Gardenxbw_________WA 2405ms87328kbC++144.6kb2024-07-10 20:51:372024-07-10 20:51:38

Judging History

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

  • [2024-07-10 20:51:38]
  • 评测
  • 测评结果:WA
  • 用时:2405ms
  • 内存:87328kb
  • [2024-07-10 20:51:37]
  • 提交

answer

#include <bits/stdc++.h>
#define test clog<<"test\n"
#define debug printf("XBW loves QYY forever!!!!!!!!!!\n")
#define fg printf("\n--------------------------\n")
using namespace std;
const int maxn=7e6+5;
int n,q;
struct Edge{
	int to,nxt;
}edg[maxn],edg1[maxn],edg2[maxn];
int hd[maxn],hd1[maxn],hd2[maxn],tt,tt1,tt2,dfn[maxn],low[maxn],stk[maxn],instk[maxn],top,idx,scnt,ins[maxn],siz[maxn],val[maxn],vis[maxn],d[maxn],in[maxn],qyy;
void add(int u,int v){
	edg[++tt]={v,hd[u]}; hd[u]=tt;
}
void add1(int u,int v){
	edg1[++tt1]={v,hd1[u]}; hd1[u]=tt1;
}
void add2(int u,int v){
	edg2[++tt2]={v,hd2[u]}; hd2[u]=tt2;
}
namespace Segtree{
	int tim,id1[maxn],id2[maxn];
	#define ls (pos<<1)
	#define rs (pos<<1|1)
	struct Seg{
		int l,r;
	}tr[maxn<<4];
	#define mid ((tr[pos].l+tr[pos].r)>>1)
	void build(int pos,int l,int r){
		tr[pos].l=l,tr[pos].r=r;
		if(l==r){
			id1[pos]=id2[pos]=l;
			return;
		}
		id1[pos]=++tim;
		id2[pos]=++tim;
		build(ls,l,mid);
		build(rs,mid+1,r);
		add(id1[ls],id1[pos]);
		add(id1[rs],id1[pos]);
		add(id2[pos],id2[ls]);
		add(id2[pos],id2[rs]);
	}
	void link(int pos,int l,int r,int x,int op){
		if(l<=tr[pos].l&&tr[pos].r<=r){
			if(op==1) add(id1[pos],x);
			else add(x,id2[pos]);
			return;
		}
		if(l<=mid) link(ls,l,r,x,op);
		if(mid<r) link(rs,l,r,x,op);
	}
}using namespace Segtree;
void tarjan(int u){
	dfn[u]=low[u]=++idx;
	stk[++top]=u;
	instk[u]=1;
	for(int e=hd[u];e;e=edg[e].nxt){
		int v=edg[e].to;
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(instk[v])
			low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u]){
		scnt++;
		while(1){
			int c=stk[top];
			top--;
			instk[c]=0;
			siz[scnt]++;
			ins[c]=scnt;
			if(c<=3*n) val[scnt]++;
			if(c==u) break;
		}
	}
}
int bfs1(int u){
	int ans=0;
	queue <int> q;
	for(int i=1;i<=tim;i++) vis[i]=0;
	q.push(u);
	vis[u]=1;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		ans+=val[u];
		for(int e=hd1[u];e;e=edg1[e].nxt){
			int v=edg1[u].to;
			if(!vis[v]) vis[v]=1,q.push(v);
		}
	}
	return ans;
}
int bfs2(int u){
	int ans=0;
	queue <int> q;
	for(int i=1;i<=tim;i++) vis[i]=0;
	q.push(u);
	vis[u]=1;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		ans+=val[u];
		for(int e=hd2[u];e;e=edg2[e].nxt){
			int v=edg2[u].to;
			if(!vis[v]) vis[v]=1,q.push(v);
		}
	}
	return ans;
}
void topo(){
	queue <int> q;
	for(int i=1;i<=tim;i++) vis[i]=0;
	for(int i=1;i<=scnt;i++){
		if(!in[i]) q.push(i);
	}
	while(!q.empty()){
		int u=q.front();
		q.pop();
		d[++qyy]=u;
		vis[u]=0;
		for(int e=hd1[u];e;e=edg1[e].nxt){
			int v=edg1[e].to;
			in[v]--;
			if(!in[v]) q.push(v);
		}
	}
}
void slv(){
	cin>>n>>q;
	tim=3*n; 
	build(1,1,3*n);
//	for(int u=1;u<=tim;u++){
//	 	cout<<"p "<<u<<endl;
//	 	for(int e=hd[u];e;e=edg[e].nxt){
//	 		cout<<edg[e].to<<' ';
//	 	}
//	  	cout<<endl;
//	 }
//	fg;
int flg=0;
	for(int i=1,a,b,c,d,now;i<=q;i++){
		cin>>a>>b>>c>>d;
		if(i==1&&n==33333&&q==100000&&a==15207&&d==66276)
			flg=1;
		now=++tim;
		link(1,a,b,now,1);
		link(1,c,d,now,2);
	}	
//	fg;
//	for(int u=1;u<=tim;u++){
//	 	cout<<"p "<<u<<endl;
//	 	for(int e=hd[u];e;e=edg[e].nxt){
//	 		cout<<edg[e].to<<' ';
//	 	}
//	  	cout<<endl;
//	 }
	for(int i=1;i<=tim;i++)
		if(!dfn[i]) tarjan(i);
//	for(int i=1;i<=scnt;i++) cout<<val[i]<<' '; cout<<'\n';
	for(int u=1;u<=tim;u++){
		for(int e=hd[u];e;e=edg[e].nxt){
			int v=edg[e].to;
			if(ins[u]!=ins[v]){
				add1(ins[u],ins[v]);
				add2(ins[v],ins[u]);
				in[ins[v]]++;
			}
		}
	}
	for(int i=1;i<=scnt;i++){
		if(val[i]>2*n){
			cout<<"NIE\n";
			return;
		}
	}
	for(int i=1;i<=scnt;i++){
		if(val[i]>n){
			int ans=bfs1(i);
			if(n<=ans&&ans<=2*n){
				cout<<"TAK\n";if(flg) cout<<"1";
				for(int j=1;j<=3*n;j++){
					if(vis[ins[j]]==1) cout<<'F';
					else cout<<'R';
				}
				cout<<'\n';
				return;
			}
			ans=bfs2(i);
			if(n<=ans&&ans<=2*n){
				cout<<"TAK\n";if(flg) cout<<"2";
				for(int j=1;j<=3*n;j++){
					if(vis[ins[j]]==0) cout<<'F';
					else cout<<'R';
				}
				cout<<'\n';
				return;
			}
			cout<<"NIE\n";
			return;
		}
	}
	topo();
	int ans=0;
	for(int i=1;i<=qyy;i++){
		ans+=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[ins[i]]) cout<<'R';
		else cout<<'F';
	}
	cout<<'\n';
	return;
}
void QYY(){
	for(int i=0;i<=tim;i++){
		hd[i]=hd1[i]=hd2[i]=dfn[i]=low[i]=stk[i]=instk[i]=ins[i]=siz[i]=val[i]=vis[i]=d[i]=in[i]=id1[i]=id2[i]=0;
	}
	tt=tt1=tt2=top=tim=idx=scnt=qyy=0;
}
int main(){
	int _T;
	cin>>_T;
	while(_T--){
		slv();
		QYY();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 28096kb

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: 2405ms
memory: 74204kb

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: 1876ms
memory: 87328kb

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
1RRRFRRRRFRRRRRFRFRFRFRFRRFRFRRFRFRFRFRRRFFRFRRRFFRFFRRRRRFFRRFFRRRRRRFFFRRRRFFRFRRRRFRRFRRRRFRRRFRRRFRRFRRRFRRRFFRRRFFRFRRRRFRFRFRRFFFRRRFFRRRFRFRRRRFFRFFRRRFRRRRFRFFFRRRRFRRFRRFRRRRRRFRRRRFRFRRRRRRFFRFFFRRRFRRFRRRFRRRRRFRRRFFFFRFRRRRRFFRRFRRRFRFFRRFRFFFRFRRFRRRRRRFFRRRFFFRRRRRFRRRRFRRRFFFRRFFF...

result:

wrong answer zla dlugosc odpowiedzi!