QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305016#5504. Flower Gardenushg8877WA 3ms59936kbC++143.1kb2024-01-14 14:26:522024-01-14 14:26:53

Judging History

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

  • [2024-01-14 14:26:53]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:59936kb
  • [2024-01-14 14:26:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=1e5+5;
int tot,n,q;
vector<int> edg[MAXN<<3],grp[MAXN<<3],rev[MAXN<<3];
int scc[MAXN<<3],val[MAXN<<3],dfn[MAXN<<3],low[MAXN<<3],cnt,snt;
int st[MAXN<<3],d[MAXN<<3],top;bool inq[MAXN<<3],ans[MAXN<<3]; 
struct segt1{
int rep[MAXN<<2];
void build(int id=1,int l=1,int r=n){
	if(l==r){
		rep[id]=l;
		return;
	} 
	rep[id]=++tot;
	int mid=l+r>>1;
	build(id<<1,l,mid);build(id<<1|1,mid+1,r);
	edg[rep[id<<1]].push_back(rep[id]);
	edg[rep[id<<1|1]].push_back(rep[id]);
}
void link(int L,int R,int x,int id=1,int l=1,int r=n){
	if(L<=l&&r<=R){
		edg[rep[id]].push_back(x);
		return;
	} 
	int mid=l+r>>1;
	if(L<=mid) link(L,R,x,id<<1,l,mid);
	else link(L,R,x,id<<1|1,mid+1,r);
}
}T1; 
struct segt2{
int rep[MAXN<<2];
void build(int id=1,int l=1,int r=n){
	if(l==r){
		rep[id]=l;
		return;
	} 
	rep[id]=++tot;
	int mid=l+r>>1;
	build(id<<1,l,mid);build(id<<1|1,mid+1,r);
	edg[rep[id]].push_back(rep[id<<1]);
	edg[rep[id]].push_back(rep[id<<1|1]);
}
void link(int L,int R,int x,int id=1,int l=1,int r=n){
	if(L<=l&&r<=R){
		edg[x].push_back(rep[id]);
		return;
	} 
	int mid=l+r>>1;
	if(L<=mid) link(L,R,x,id<<1,l,mid);
	else link(L,R,x,id<<1|1,mid+1,r);
}
}T2; 
void tarjan(int u){
	low[u]=dfn[u]=++cnt;
	st[++top]=u;inq[u]=true;
	for(int v:edg[u]){
		if(!dfn[v]){
			tarjan(v);
			low[v]=min(low[v],low[u]);
		}else if(inq[v]) low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]){
		++snt;
		while(st[top+1]!=u){
			inq[st[top]]=false;
			scc[st[top--]]=snt;
		}
	}
}
void output(){
	cout<<"TAK"<<endl;
	for(int i=1;i<=n;i++) cout<<"RV"[ans[scc[i]]];
	cout<<endl;
}
void init(){
	for(int i=1;i<=tot;i++){
		edg[i].clear(),grp[i].clear(),rev[i].clear();
		scc[i]=dfn[i]=low[i]=val[i]=0;
		st[i]=d[i]=inq[i]=ans[i]=0;
	}
	cnt=snt=top=tot=0;n=q=0;
}
void solve(){
	cin>>n>>q;n*=3;
	tot=n;
	T1.build();T2.build();
	for(int i=1;i<=q;i++){
		int x=++tot,y=++tot,a,b,c,d;
		cin>>a>>b>>c>>d;
		T1.link(a,b,x);T2.link(c,d,y);
		edg[x].push_back(y);
	}
	cnt=0;
	for(int i=1;i<=tot;i++) if(!dfn[i]) tarjan(i);
	for(int i=1;i<=n;i++) val[scc[i]]++;
	for(int i=1;i<=tot;i++) for(int j:edg[i]) if(scc[i]!=scc[j])
		grp[scc[i]].push_back(scc[j]),rev[scc[j]].push_back(scc[i]);
	for(int i=1;i<=snt;i++) d[i]=grp[i].size();
	queue<int> q;
	for(int i=1;i<=snt;i++) if(d[i]==0&&val[i]<=n/3) q.push(i);
	int sum=0;
	while(!q.empty()){
		int u=q.front();q.pop();
		sum+=val[u];ans[u]=true;
		if(sum>=n/3) return output(),init();
		for(int v:rev[u]) if(--d[v]==0&&val[v]<=n/3) q.push(v);
	}
	for(int i=1;i<=snt;i++) if(d[i]>=n/3){
		for(int i=1;i<=snt;i++) ans[i]=false;
		while(!q.empty()) q.pop();
		sum=0;q.push(i);ans[i]=true;
		while(!q.empty()){
			int u=q.front();q.pop();
			sum+=val[u];
			for(int v:grp[u]) if(!ans[v]){
				ans[v]=true;
				q.push(v);
			}
		}
		if(sum<=2*n/3) return output(),init();
	}
	cout<<"NIE"<<endl;
	return init();
}
int main(){
	ios::sync_with_stdio(false);
	int _;cin>>_;
	while(_--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 59936kb

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

result:

wrong answer odpowiedz zawiera znak inny niz R oraz F!