QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99137#5504. Flower GardenfansizheWA 3339ms162956kbC++233.4kb2023-04-21 11:57:162023-04-21 11:57:18

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 11:57:18]
  • 评测
  • 测评结果:WA
  • 用时:3339ms
  • 内存:162956kb
  • [2023-04-21 11:57:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,pnum;
vector<int> edge[1000005];
int dfn[1000005],low[1000005],cnt;
stack<int> st;int ins[1000005];
int col[1000005],tot;
vector<int> e1[1000005],e2[1000005];
int deg[1000005];
int vis[1000005];
int num[1000005];
queue<int> que;
int tot1,tot2;
int ch[1000005][2];
void addedge(int x,int y){edge[x].push_back(y);}
void build1(int k,int l,int r){
	if(l==r){
		addedge(l,k+n);
		return;
	}
	int mid=l+r>>1;
	ch[k][0]=++tot1;build1(ch[k][0],l,mid);
	ch[k][1]=++tot1;build1(ch[k][1],mid+1,r);
	addedge(ch[k][0]+n,k+n);
	addedge(ch[k][1]+n,k+n);
}
void build2(int k,int l,int r){
	if(l==r){
		addedge(k+n+tot1,l);
		return;
	}
	int mid=l+r>>1;
	ch[k][0]=++tot2;build2(ch[k][0],l,mid);
	ch[k][1]=++tot2;build2(ch[k][1],mid+1,r);
	addedge(k+n+tot1,ch[k][0]+n+tot1);
	addedge(k+n+tot1,ch[k][1]+n+tot1);
}
void change1(int k,int l,int r,int x,int y,int z){
	if(l>=x&&r<=y){
		addedge(k+n,z);
		return;
	}
	int mid=l+r>>1;
	if(x<=mid)change1(ch[k][0],l,mid,x,y,z);
	if(y>mid)change1(ch[k][1],mid+1,r,x,y,z);
}
void change2(int k,int l,int r,int x,int y,int z){
	if(l>=x&&r<=y){
		addedge(z,k+n+tot1);
		return;
	}
	int mid=l+r>>1;
	if(x<=mid)change2(ch[k][0],l,mid,x,y,z);
	if(y>mid)change2(ch[k][1],mid+1,r,x,y,z);
}
void Tarjan(int x){
	dfn[x]=low[x]=++cnt;
	ins[x]=1;st.push(x);
	for(int y:edge[x])
		if(!dfn[y])Tarjan(y),low[x]=min(low[x],low[y]);
		else if(ins[y])low[x]=min(low[x],dfn[y]);
	if(low[x]==dfn[x]){
		tot++;int y;num[tot]=0;
		do{
			y=st.top();st.pop();
			col[y]=tot;num[tot]+=(y<=n);ins[y]=0;
		}while(y!=x);
	}
}
int main(){
	int _;scanf("%d",&_);
	while(_--){
		scanf("%d%d",&n,&m);n*=3;
		tot1=1,tot2=1;
		build1(1,1,n);
		build2(1,1,n);
		for(int i=1;i<=m;i++){
			int l1,r1,l2,r2;
			scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
			change1(1,1,n,l1,r1,tot1+tot2+i);
			change2(1,1,n,l2,r2,tot1+tot2+i);
		}
		pnum=n+tot1+tot2+m;cnt=tot=0;
		for(int i=1;i<=pnum;i++)if(!dfn[i])Tarjan(i);
		for(int i=1;i<=tot;i++)e1[i].clear(),e2[i].clear(),deg[i]=0;
		for(int i=1;i<=pnum;i++)
			for(int j:edge[i])if(col[i]!=col[j])
				e1[col[i]].push_back(col[j]),e2[col[j]].push_back(col[i]);
		int s=0,sum=0;
		for(int i=1;i<=tot;i++)if(num[i]>=n)s=i;
		for(int i=1;i<=tot;i++)vis[i]=0;
		if(!s){
			for(int i=1;i<=tot;i++)for(int j:e2[i])deg[j]++;
			for(int i=1;i<=tot;i++)if(!deg[i])que.push(i);
			while(!que.empty()){
				int x=que.front();que.pop();
				sum+=num[x];vis[x]=1;
				if(sum>=n/3)break;
				for(int y:e2[x])if(!--deg[y])que.push(y);
			}
			puts("TAK");
			for(int i=1;i<=n;i++)if(vis[col[i]])putchar('F');else putchar('R');puts("");
			while(!que.empty())que.pop();
		}else{
			que.push(s);
			while(!que.empty()){
				int x=que.front();que.pop();
				sum+=num[x];
				for(int y:e1[x])if(!vis[y])que.push(y),vis[y]=1;
			}
			if(sum<=n/3*2){
				puts("TAK");
				for(int i=1;i<=n;i++)if(vis[col[i]])putchar('F');else putchar('R');puts("");
			}else{
				sum=0;
				for(int i=1;i<=tot;i++)vis[i]=0;
				que.push(s);
				while(!que.empty()){
					int x=que.front();que.pop();
					sum+=num[x];
					for(int y:e2[x])if(!vis[y])que.push(y),vis[y]=1;
				}
				if(sum<=n/3*2){
					puts("TAK");
					for(int i=1;i<=n;i++)if(vis[col[i]])putchar('F');else putchar('R');puts("");
				}else puts("NIE");
			}
		}
		for(int i=1;i<=pnum;i++)edge[i].clear(),dfn[i]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 78648kb

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

result:

ok good!

Test #2:

score: -100
Wrong Answer
time: 3339ms
memory: 162956kb

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:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

wrong answer zla odpowiedz!