QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#534472#5504. Flower Gardenpjt_camelliaWA 1562ms259724kbC++144.0kb2024-08-27 10:59:592024-08-27 10:59:59

Judging History

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

  • [2024-08-27 10:59:59]
  • 评测
  • 测评结果:WA
  • 用时:1562ms
  • 内存:259724kb
  • [2024-08-27 10:59:59]
  • 提交

answer

// Problem: I - Flower Garden
// Contest: Virtual Judge - 20240710 多校集训 div2 贪心与构造(pb)
// URL: https://vjudge.net/contest/639510#problem/I
// Memory Limit: 1014 MB
// Time Limit: 30000 ms
// Date: 2024-08-15 15:40:07
// 
// Powered by CP Editor (https://cpeditor.org)

/*

*/
#include <bits/stdc++.h>
#define ls k<<1
#define rs k<<1|1
using namespace std;
inline long long read(){
    long long x=0,w=0;char c=0;
    while(!isdigit(c)) {w|=c=='-';c=getchar();}
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return w?-x:x;
}
int T;
int n,q,a,b,c,d;
int id1[2000050],id2[2000500],tot;
vector<int> mp[2000500],t1[2000500],t2[2000500];
void build(int k,int l,int r){
	if(l==r){
		id1[k]=id2[k]=l;
		return;
	}
	id1[k]=++tot;
	id2[k]=++tot;
	int mid=(l+r)>>1;
	build(ls,l,mid);
	build(rs,mid+1,r);
	mp[id1[ls]].push_back(id1[k]);
	mp[id1[rs]].push_back(id1[k]);
	mp[id2[k]].push_back(id2[ls]);
	mp[id2[k]].push_back(id2[rs]);
}
void add1(int k,int l,int r,int x,int y,int to){
	if(x<=l&&r<=y){
		mp[id1[k]].push_back(to);
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid){
		add1(ls,l,mid,x,y,to);
	}
	if(y>mid){
		add1(rs,mid+1,r,x,y,to);
	}
}
void add2(int k,int l,int r,int x,int y,int u){
	if(x<=l&&r<=y){
		mp[u].push_back(id2[k]);
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid){
		add2(ls,l,mid,x,y,u);
	}
	if(y>mid){
		add2(rs,mid+1,r,x,y,u);
	}
}
stack<int> st;
int dfn[2000050],low[2000500],num,cntt,sccx[2000500],siz[2005000];
bool vis[2005000],flag;
int du[2005000];
void tj(int x){
	dfn[x]=low[x]=++num;
	if(!vis[x]){
		vis[x]=1;
		st.push(x);
	}
	for(int i:mp[x]){
		if(!dfn[i]){
			tj(i);
			low[x]=min(low[x],low[i]);
		}
		else if(vis[i]){
			low[x]=min(low[x],dfn[i]);
		}
	}
	if(dfn[x]==low[x]){
		cntt++;
		while(st.top()!=x){
			vis[st.top()]=0;
			sccx[st.top()]=cntt;
			st.pop();
		}
		vis[st.top()]=0;
		sccx[st.top()]=cntt;
		st.pop();
	}
}
int main(){ 
	T=read();
	while(T--){
		n=read();
		q=read();
		tot=n*3;
		build(1,1,tot);
		for(int i=1;i<=q;i++){
			a=read(),b=read();
			c=read(),d=read();
			int now=++tot;
			add1(1,1,n*3,a,b,now);
			add2(1,1,n*3,c,d,now);
		}
		for(int i=1;i<=tot;i++){
			if(!dfn[i]){
				tj(i);
			}
		}
		for(int i=1;i<=n*3;i++){
			siz[sccx[i]]++;
		}
		for(int i=1;i<=tot;i++){
			for(int j:mp[i]){
				if(sccx[i]!=sccx[j]){
					t1[sccx[i]].push_back(sccx[j]);
					t2[sccx[j]].push_back(sccx[i]);
				}
			}
		}
		queue<int> q;
		for(int i=1;i<=cntt;i++){
			du[i]=t1[i].size();
			if(!du[i]){
				q.push(i);
			}
		}
		int sum=0;
		while(!q.empty()){
			int u=q.front();
			q.pop();
			if(siz[u]>=n){
				continue;
			}
			vis[u]=1;
			if(sum>=n&&sum<=2*n){
				flag=1;
				break;
			}
			for(int v:t2[u]){
				if(!--du[v]){
					q.push(v);
				}
			}
		}
		if(!flag){
			for(int i=1;i<=cntt;i++){
				if(siz[i]>=n){
					for(int j=1;j<=cntt;j++){
						du[j]=0;
						vis[j]=0;
					}
					for(int j=1;j<=cntt;j++){
						for(int v:t1[j]){
							du[v]++;
						}
					}
					vis[i]=1;
					while(!q.empty()){
						q.pop();
					}
					for(int j=1;j<=cntt;j++){
						if(!du[j]){
							q.push(j);
						}
					}
					while(!q.empty()){
						int u=q.front();
						q.pop();
						for(int v:t1[u]){
							vis[v]|=vis[u];
							if(!--du[v]){
								q.push(v);
							}
						}
					}
					sum=0;
					for(int j=1;j<=cntt;j++){
						if(vis[j]){
							sum+=siz[j];
						}
					}
					if(sum>=n&&sum<=n*2){
						flag=1;
						break;
					}
				}
			}
		}
		if(flag){
			printf("TAK\n");
			for(int i=1;i<=n*3;i++){
				printf("%c",vis[sccx[i]]?'F':'R');
			}
			printf("\n");
		}
		else{
			printf("NIE\n");
		}
		flag=0;
		while(!q.empty()){
			q.pop();
		}
		for(int i=1;i<=tot;i++){
			mp[i].clear();
			t1[i].clear();
			t2[i].clear();
			dfn[i]=low[i]=sccx[i]=siz[i]=du[i]=vis[i]=0;
			id1[i]=id2[i]=0;
		}
		cntt=num=0;
	}
	return 0; 
}
/*

*/

详细

Test #1:

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

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: 1562ms
memory: 227076kb

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: 1461ms
memory: 259724kb

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:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

wrong answer zla odpowiedz!