QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262214#5504. Flower Gardensix-floor-slip-liuWA 6645ms293296kbC++144.4kb2023-11-23 16:43:342023-11-23 16:43:34

Judging History

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

  • [2023-11-23 16:43:34]
  • 评测
  • 测评结果:WA
  • 用时:6645ms
  • 内存:293296kb
  • [2023-11-23 16:43:34]
  • 提交

answer

#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define forup(i,s,e) for(int i=(s);i<=(e);i++)
#define fordown(i,s,e) for(int i=(s);i>=(e);i--)
using namespace std;
using pii=pair<int,int>;
#define fi first
#define se second
#define mkp make_pair
#define gc getchar()
inline int read(){
    int x=0,f=1;char c;
    while(!isdigit(c=gc)) if(c=='-') f=-1;
    while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=gc;}
    return x*f;
}
#undef gc
const int N=123456,inf=0x3f3f3f3f;
int n,q,cntn;
struct edge{
	int v,nxt;
}e[12345678];
int head[N*9*2],cnte;
void adde(int u,int v){
	e[++cnte]=edge{v,head[u]};head[u]=cnte;
}
int dfn[N*9*2],low[N*9*2],Tm,blg[N*9*2],csc,ist[N*9*2];
stack<int> stk;
int col[N*9*2],sz[N*9*2];
vector<pii> sve;
void Tarjan(int x){
	low[x]=dfn[x]=++Tm;
	stk.push(x);ist[x]=1;
	for(int i=head[x];i;i=e[i].nxt){
		int v=e[i].v;
		if(!dfn[v]){
			Tarjan(v);
			low[x]=min(low[x],low[v]);
		}else if(ist[v]){
			low[x]=min(low[x],dfn[v]);
		}
	}
	if(dfn[x]==low[x]){
		++csc;sz[csc]=col[csc]=0;
		while(stk.top()!=x){
			int u=stk.top();
			ist[u]=0;
			blg[u]=csc;
			if(u<=n*3){
				++sz[csc];
			}
			for(int i=head[u];i;i=e[i].nxt){
				int v=e[i].v;
				if(low[v]==low[u]) continue;
				sve.push_back(mkp(u,v));
			}
			stk.pop();
		}
		int u=stk.top();
		ist[u]=0;
		blg[u]=csc;
		if(u<=n*3){
			++sz[csc];
		}
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(low[v]==low[u]) continue;
			sve.push_back(mkp(u,v));
		}
		stk.pop();
	}
}
int newnode(){
	++cntn;
	head[cntn]=0;
	dfn[cntn]=low[cntn]=blg[cntn]=ist[cntn]=0;
	return cntn;
}
struct SegTree{
	#define mid ((l+r)>>1)
	#define lson l,mid,id<<1
	#define rson mid+1,r,id<<1|1
	int num[N<<2],co,tp;
	void Build(int l=1,int r=3*n,int id=1){
		if(l==r){
			num[id]=l+co*(n*3);
			if(tp==0){
				adde(num[id>>1],num[id]);
			}else{
				adde(num[id],num[id>>1]);
			}
			return;
		}
		if(id>1){
			num[id]=newnode();
			if(tp==0){
				adde(num[id>>1],num[id]);
			}else{
				adde(num[id],num[id>>1]);
			}
		}
		Build(lson);Build(rson);
	}
	void init(int _co,int _tp){
		co=_co;tp=_tp;
		num[1]=newnode();
		Build();
	}
	void Link(int L,int R,int X,int l=1,int r=3*n,int id=1){
		if(L<=l&&r<=R){
			if(tp==0){
				adde(X,num[id]);
			}else{
				adde(num[id],X);
			}
			return;
		}
		if(L<=mid) Link(L,R,X,lson);
		if(mid< R) Link(L,R,X,rson);
	}
};
SegTree t[2][2];
namespace ANS{
	vector<int> e[N*9*2],re[N*9*2];
	int deg[N*9*2];
	int dfs(int x){
		int res=sz[x];
		for(auto i:re[x]){
			if(col[i]) continue;
			res+=dfs(i);
		}
		return res;
	}
	bool work2(){
		forup(i,1,csc){
			col[i]=0;
		}
		fordown(i,csc,1){
			if(sz[i]>n){
				return dfs(i)<=n*2;
			}
		}
		return false;
	}
	void work(){
		forup(i,1,csc){
			e[i].clear();
			re[i].clear();
			deg[i]=0;
		}
		set<pii> ss;
		for(auto i:sve){
			int u=i.fi,v=i.se;
			int fu=blg[u],fv=blg[v];
			if(fu==fv||ss.count(mkp(fu,fv))) continue;
			ss.insert(mkp(fu,fv));
			e[fu].push_back(fv);
			re[fv].push_back(fu);
			++deg[fv];
		}
		vector<int> vec,v1;
		forup(i,1,csc){
			if(deg[i]==0&&sz[i]<=n){
				vec.push_back(i);
			}
		}
		vector<int> seq;
		while(vec.size()){
			v1.clear();
			for(auto u:vec){
				if(sz[u]!=0) seq.push_back(u);
				for(auto v:e[u]){
					--deg[v];
					if(deg[v]==0&&sz[v]<=n) v1.push_back(v);
				}
			}
			vec=v1;
		}
		int sum=0;
		for(auto i:seq){
			sum+=sz[i];
			col[i]=1;
			if(sum>=n){
				break;
			}
		}
		if(sum>=n&&sum<=n*2){
			puts("TAK");
		}else{
			if(work2()){
				puts("TAK");
			}else{
				puts("NIE");
				return;
			}
		}
		forup(i,1,n*3){
			putchar(col[blg[i]]?'F':'R');
		}
		puts("");
	}
}
void solve(){
	n=read();q=read();
	cnte=0;cntn=n*6;
	forup(i,1,n*6){
		head[i]=0;
		dfn[i]=low[i]=blg[i]=ist[i]=0;
	}
	forup(i,0,1){
		forup(j,0,1){
			t[i][j].init(i,j);
		}
	}
	forup(i,1,q){
		int l1=read(),r1=read(),l2=read(),r2=read();
		int nw=newnode();
		t[1][1].Link(l1,r1,nw);t[1][0].Link(l2,r2,nw);
		nw=newnode();
		t[0][1].Link(l2,r2,nw);t[0][0].Link(l1,r1,nw);
	}
	sve.clear();
	Tm=csc=0;
	forup(i,1,cntn){
		if(!dfn[i]) Tarjan(i);
	}
	forup(i,1,csc){
		if(sz[i]>=n*2){
			puts("NIE");
			return;
		}
	}
	ANS::work();
}
signed main(){
	int t=read();
	while(t--){
		solve();
	}
}
/*
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

*/

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 130392kb

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: 0
Accepted
time: 4952ms
memory: 286624kb

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: 6645ms
memory: 293296kb

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:

NIE
TAK
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

result:

wrong answer zla odpowiedz!