QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471761#5504. Flower GardenmaojunWA 0ms20404kbC++232.3kb2024-07-11 08:06:422024-07-11 08:06:43

Judging History

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

  • [2024-07-11 08:06:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:20404kb
  • [2024-07-11 08:06:42]
  • 提交

answer

#include<bits/stdc++.h>
#define mem(a,n) memset(a+1,0,n*sizeof*a)
using namespace std;

const int N=2e6;
int n,q;
vector<int>G[N];
#define eb emplace_back
inline void Add(int u,int v){G[u].eb(v);}

int idx,t1[N],t2[N];
#define ls p<<1
#define rs p<<1|1
#define mid (l+r>>1)
#define Ls ls,l,mid
#define Rs rs,mid+1,r
#define all 1,1,n*3
void bld(int p,int l,int r){
	if(l==r){t1[p]=t2[p]=l;return;}
	t1[p]=++idx;t2[p]=++idx;
	bld(Ls);bld(Rs);
	Add(t1[ls],t1[p]);Add(t1[rs],t1[p]);
	Add(t2[p],t2[ls]);Add(t2[p],t2[rs]);
}
void link(int p,int l,int r,int L,int R,int k){
	if(L<=l&&r<=R)return k>0?Add(t1[p],k):Add(-k,t2[p]);
	if(L<=mid)link(Ls,L,R,k);if(R>mid)link(Rs,L,R,k);
}

int dfc,dfn[N],low[N],top,stk[N];bool ins[N];
int m,col[N],siz[N];
void tarjan(int u){
	low[u]=dfn[u]=++dfc;ins[stk[++top]=u]=1;
	for(int v:G[u])
		if(!dfn[v]){tarjan(v);low[u]=min(low[u],low[v]);}
		else if(ins[v])low[u]=min(low[u],dfn[v]);
	if(low[u]==dfn[u]){
		m++;do{
			int v=stk[top--];
			col[v]=m;siz[m]+=v<=n*3;ins[v]=0;
		}while(ins[u]);
	}
}
vector<int>T[N],rT[N];int deg[N];
inline void AddT(int u,int v){if(u^v){T[u].eb(v);rT[v].eb(u);deg[u]++;}}
bool vis[N];
inline bool topSort(){
	mem(vis,m);queue<int>q;
	for(int i=1;i<=m;i++)if(!deg[i])q.push(i);
	int now=0;
	while(!q.empty()){
		int u=q.front();q.pop();
		if(now+siz[u]>n*2)continue;
		vis[u]=true;
		if((now+=siz[u])>=n)return true;
		for(int v:rT[u])if(!--deg[v])q.push(v);
	}
	return false;
}
inline int dfs(int u){
	if(vis[u])return 0;vis[u]=1;
	int r=siz[u];for(int v:T[u])r+=dfs(v);
	return r;
}
inline bool solve(){
	scanf("%d%d",&n,&q);
	idx=n*3;bld(all);
	for(int a,b,c,d;q--;){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		link(all,a,b,++idx);link(all,c,d,-idx);
	}
	for(int i=1;i<=idx;i++)if(!dfn[i])tarjan(i);
	for(int u=1;u<=idx;u++)for(int v:G[u])AddT(col[u],col[v]);
	if(topSort())return true;
	for(int i=1;i<=m;i++)if(siz[i]>=n)
		if(mem(vis,m);dfs(i)<=n*2)return true;
	return false;
}
int main(){
	int CASE;scanf("%d",&CASE);
	while(CASE--){
		if(solve()){
			puts("TAK");
			for(int i=1;i<=n*3;i++)putchar(vis[col[i]]?'R':'F');
			puts("");
		}else puts("NIE");
		for(int i=1;i<=idx;i++)G[i].clear();
		for(int i=1;i<=m;i++){T[i].clear();rT[i].clear();}
		mem(dfn,idx);dfc=top=0;mem(ins,idx);mem(siz,m);mem(deg,m);m=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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!