QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#470903#5504. Flower GardenczcWA 0ms28588kbC++234.4kb2024-07-10 16:52:552024-07-10 16:52:55

Judging History

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

  • [2024-07-10 16:52:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:28588kb
  • [2024-07-10 16:52:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=1e5+5;
struct tree{
	int id1,id2;
}T[maxn<<2];
int tot;
vector<int> G[maxn<<3];
#define lc (rt<<1)
#define rc (rt<<1|1) 
int h[maxn<<3],vs[maxn<<3];
inline void build(int rt,int l,int r){
	if(l==r){
		T[rt].id1=T[rt].id2=++tot;
		G[tot].clear();
		h[tot]=l;
		vs[tot]=1;
		return ;
	}
	T[rt].id1=++tot,vs[tot]=0;
	T[rt].id2=++tot,vs[tot]=0;
	G[T[rt].id1].clear();
	G[T[rt].id2].clear();
	int mid=(l+r)>>1;
	build(lc,l,mid);
	build(rc,mid+1,r);
	G[T[rt].id1].push_back(T[lc].id1),G[T[rt].id1].push_back(T[rc].id1);
	G[T[lc].id2].push_back(T[rt].id2),G[T[rc].id2].push_back(T[rt].id2);
}
vector<int> v1,v2;
inline void ask(int rt,int l,int r,int L,int R,int op){
	if(L<=l && r<=R){
		if(op) v1.push_back(T[rt].id1);
		else v2.push_back(T[rt].id2);
		return ;
	}
	int mid=(l+r)>>1;
	if(L<=mid) ask(lc,l,mid,L,R,op);
	else ask(rc,mid+1,r,L,R,op);
}
int dfn[maxn<<3],low[maxn<<3],instack[maxn<<3],scc[maxn<<3],col,tt;
stack<int> st;
inline void Tarjan(int x){
	dfn[x]=low[x]=++tt;
	st.push(x);
	instack[x]=1;
	for(auto y:G[x]){
		if(!dfn[y]){
			Tarjan(y);
			low[x]=min(low[x],low[y]);
		}
		else if(instack[y]) low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x]){
		col++;
		scc[x]=col,instack[x]=0;
		while(st.top()!=x){
			scc[st.top()]=col;
			instack[st.top()]=0;
			st.pop();
		}
		st.pop();
	}
}
int Ans[maxn];
vector<int> G2[maxn<<3],G3[maxn<<3];
int ind[maxn<<3],cd[maxn<<3],siz[maxn<<3],vvv[maxn<<3];
vector<int> vv[maxn<<3];
inline void solve(){
	scanf("%d%d",&n,&m);
	tot=0;
	build(1,1,n*3);
	for(int i=1,l1,r1,l2,r2;i<=m;i++){
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		v1.clear(),v2.clear();
		ask(1,1,n*3,l1,r1,1);
		ask(1,1,n*3,l2,r2,0);
		for(auto x:v2){
			for(auto y:v1){
				G[x].push_back(y);
			}
		}
	}
	while(!st.empty()) st.pop();
	for(int i=1;i<=tot;i++) dfn[i]=low[i]=instack[i]=scc[i]=0;
	col=tt=0; 
	for(int i=1;i<=tot;i++)
		if(!dfn[i]) Tarjan(i);
	for(int i=1;i<=n*3;i++) Ans[i]=0;
	for(int i=1;i<=col;i++) vv[i].clear(),ind[i]=0,G2[i].clear(),siz[i]=0,cd[i]=0,vvv[i]=0;
	for(int i=1;i<=tot;i++){
		assert(1<=scc[i] && scc[i]<=col);
		siz[scc[i]]+=vs[i];
		if(vs[i]) vv[scc[i]].push_back(h[i]);
		assert(siz[scc[i]]==(int)vv[scc[i]].size());
		for(auto j:G[i]){
			if(scc[i]!=scc[j]){
				G2[scc[i]].push_back(scc[j]);
				G3[scc[j]].push_back(scc[i]);
				ind[scc[j]]++,cd[scc[i]]++;
			}
		}
	}
	int ps=0;
	for(int i=1;i<=col;i++){
		if(siz[i]>2*n){
			printf("NIE\n");
			return ; 
		}
		if(siz[i]>n+1){
			ps=i;
			break;
		}
	}
	if(!ps){
		//乱选
		queue<int> q;
		int ans=0; 
		for(int i=1;i<=col;i++)
			if(!cd[i]) q.push(i);
		for(int i=1;i<=n*3;i++) assert(Ans[i]==0);
		while(!q.empty()){
			int x=q.front();
			q.pop();
			ans+=siz[x];
			for(auto y:vv[x]){
				if(Ans[y]){
					cout<<Ans[y]<<" "<<x;
					exit(0);
				}
				/*assert(Ans[y]==0),*/Ans[y]=x;
			}
			assert(siz[x]==(int)vv[x].size());
			if(ans>=n) break;
			for(auto y:G3[x]){
				cd[y]--;
				if(!cd[y]) q.push(y);
			}
		}
		puts("TAK");
//		int ctt=0;
//		for(int i=1;i<=n*3;i++){
//			if(Ans[i]) printf("R"),ctt++;
//			else printf("F");
//		}
//		assert(ans==ctt);
//		assert(n<=ctt && ctt<=2*n);
//		puts("");
		return ;
	}
	else{
		//考虑选 pos
		int ans=0;
		queue<int> q;
		q.push(ps);
		vvv[ps]=1;
		while(!q.empty()){
			int x=q.front();
			q.pop();
			ans+=siz[x]; 
			for(auto y:vv[x]) Ans[y]=1;
			for(auto y:G2[x]){
				if(!vvv[y]){
					vvv[y]=1;
					q.push(y); 
				}
			}
		}
		if(ans<=2*n){
			puts("TAK");
//			int ctt=0;
//			for(int i=1;i<=n*3;i++){
//				if(Ans[i]) printf("R"),ctt++;
//				else printf("F");
//			}
//			assert(n<=ctt && ctt<=2*n);
//			puts("");
			return ;
		}
		for(int i=1;i<=n*3;i++) Ans[i]=0;
		//考虑不选
		ans=0;
		for(int i=1;i<=col;i++)
			if(!cd[i]) q.push(i);
		while(!q.empty()){
			int x=q.front();
			q.pop();
			if(x==ps) continue;
			ans+=siz[x];
			for(auto y:vv[x]) Ans[y]=1;
			for(auto y:G3[x]){
				cd[y]--;
				if(!cd[y]) q.push(y);
			}
		}
		if(ans>=n){
			int ctt=0;
			puts("TAK");
//			for(int i=1;i<=n*3;i++){
//				if(Ans[i]) printf("R"),ctt++;
//				else printf("F");
//			}
//			puts("");
//			assert(n<=ctt && ctt<=2*n);
			return ;
		}
	}
	puts("NIE");
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 28588kb

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
NIE

result:

wrong answer odpowiedz zawiera znak inny niz R oraz F!