QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471092#5504. Flower GardenBINYUAC ✓2005ms134500kbC++143.3kb2024-07-10 17:56:152024-07-10 17:56:17

Judging History

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

  • [2024-07-10 17:56:17]
  • 评测
  • 测评结果:AC
  • 用时:2005ms
  • 内存:134500kb
  • [2024-07-10 17:56:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5,Q = 1e5,M = 3 * N + Q;
int n,m,cntnode,l1,r1,l2,r2;
int dfn[M + 5],cntdfn,cntscc,id[M + 5];
int ins[M + 5],low[M + 5],flag[M + 5],siz[M + 5];
int ls[3 * N + 5],rs[3 * N + 5];
stack <int> s;
vector <int> e[M + 5],E1[M + 5],E2[M + 5];
void adde(int u,int v,int op)
{
	if(op)swap(u,v);
	e[u].push_back(v);
}
int build(int l,int r,int op)
{
	if(l == r)return l;
	int id = ++cntnode;
	int mid = l + r >> 1;
	ls[id] = build(l,mid,op);
	rs[id] = build(mid + 1,r,op);
	adde(id,ls[id],op);adde(id,rs[id],op);
	return id;
}
void Adde(int id,int l,int r,int st,int en,int u,int op)
{
	if(l >= st&&r <= en)
		return adde(u,id,op);
	int mid = l + r >> 1;
	if(st <= mid)Adde(ls[id],l,mid,st,en,u,op);
	if(en > mid)Adde(rs[id],mid + 1,r,st,en,u,op);
}
void tarjan(int u)
{
	dfn[u] = low[u] = ++cntdfn;
	s.push(u);ins[u] = 1;
	for(auto v : e[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])
	{
		ins[u] = 0;id[u] = ++cntscc;
		while(s.top() != u)
			ins[s.top()] = 0,id[s.top()] = cntscc,s.pop();
		s.pop();
	}
}
void write()
{
	puts("TAK");
	for(int i = 1;i <= 3 * n;i++)
		if(flag[id[i]])putchar('R');
		else putchar('F');
	puts("");
}
int solve1(int root)
{
	queue <int> q;
	int sum = 0;
	q.push(root);
	flag[root] = 1;
	while(!q.empty())
	{
		int u = q.front();q.pop();
		sum += siz[u];
		for(auto v : E1[u])
			if(!flag[v])
				flag[v] = 1,q.push(v);
	}
	return sum;
}
int solve2(int root)
{
	queue <int> q;
	int sum = 0;
	q.push(root);
	flag[root] = 1;
	while(!q.empty())
	{
		int u = q.front();q.pop();
		sum += siz[u];
		for(auto v : E2[u])
			if(!flag[v])
				flag[v] = 1,q.push(v);
	}
	return sum;
}
bool Debug;
void solve()
{
	scanf("%d %d",&n,&m);
	cntnode = 3 * n;cntdfn = 0;cntscc = 0;
	int root0 = build(1,3 * n,0);
	int root1 = build(1,3 * n,1);
	for(int i = 1;i <= m;i++)
	{
		scanf("%d %d %d %d",&l1,&r1,&l2,&r2);
		if(l1 == 15207&&r1 == 33614)Debug = 1;
		++cntnode;
		Adde(root1,1,3 * n,l1,r1,cntnode,1);
		Adde(root0,1,3 * n,l2,r2,cntnode,0);
	}
	for(int i = 1;i <= cntnode;i++)
		if(!dfn[i])tarjan(i);
	for(int i = 1;i <= cntnode;i++)
		for(auto v : e[i])
			if(id[i] != id[v])
				E1[id[i]].push_back(id[v]),
				E2[id[v]].push_back(id[i]);
	for(int i = 1;i <= 3 * n;i++)siz[id[i]]++;
	int F = 0;
	for(int i = 1;i <= cntscc;i++)
		if(siz[i] >= n)
		{
			F = 1;
			for(int j = 1;j <= cntscc;j++)flag[j] = 0;
			int sum = solve1(i);
			if(sum <= 2 * n)
			{
				F = 2;
				for(int j = 1;j <= cntscc;j++)flag[j] ^= 1;
				write();
				break;
			}
			for(int j = 1;j <= cntscc;j++)flag[j] = 0;
			sum = solve2(i);
			if(sum <= 2 * n)
			{
				F = 2; 
				write();
				break; 
			}
		}
	if(F == 1)puts("NIE");
	else if(F == 0)
	{
		int sum = 0;
		for(int i = cntscc;~i;i--)
		{
			sum += siz[i];
			flag[i] = 1;
			if(sum >= n)break;
		}
		write();
	}
	for(int i = 1;i <= cntnode;i++)e[i].clear(),dfn[i] = 0;
	for(int i = 1;i <= cntscc;i++)
		flag[i] = 0,E1[i].clear(),E2[i].clear(),siz[i] = 0;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)solve();
}
/*
1
3 6
9 9 1 1
5 9 2 3
2 4 8 9
4 5 6 6
9 9 6 7
5 7 9 9
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 42076kb

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: 2005ms
memory: 103076kb

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: 0
Accepted
time: 1848ms
memory: 132480kb

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:

ok good!

Test #4:

score: 0
Accepted
time: 1747ms
memory: 120732kb

input:

10
33333 100000
2646 2646 6430 6446
82226 82231 15128 15132
877 877 85831 88474
51389 79196 37573 37573
38030 38030 14248 14280
63032 68489 81074 81074
46468 46468 7403 7487
19864 20058 97979 97979
71640 71833 8558 8558
12121 12434 82481 82481
32901 32901 1899 2162
65312 77886 75969 75974
87983 8798...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #5:

score: 0
Accepted
time: 327ms
memory: 42904kb

input:

87005
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
1 1
1 3 2 3
1 2
1 1 2 2
2 2 1 1
1 2
1 3 1 1
1 1 1 3
4 20
3 5 6 12
4 5 7 11
1 1 2 2
3 4 7 12
3 5 10 10
3 5 8 8
4 4 9 11
4 4 7 7
1 1 9 10
3 4 6 9
3 5 11 12
3 3 7 9
3 5 2 2
4 5 2 2
1 1 7 11
1 1 10 10
3 5 7 8
4 4 2 2
1 1 2 2
4 5 8 10
4 12
11 ...

output:

TAK
RRF
NIE
TAK
RFF
TAK
FFR
NIE
TAK
FFRRRFFFFFFR
TAK
FFFFFFFFRRRR
NIE
TAK
FFFFFRRFFFFFRRR
TAK
FFRRRRFFFFFF
TAK
FFFFFFRRRRFF
TAK
FFFFFFFRFFFRRRR
TAK
FFRRRRFFFFFF
TAK
FFRRFFFFFRRRFFF
NIE
TAK
FFFFFFRRRFFR
NIE
TAK
RRFFFRRFF
NIE
TAK
FFFFFFRRR
TAK
FRRRFFFFFFRF
TAK
RRFFRFRFFFFFRFF
TAK
FFRRRRFFFFFF
NIE
TAK
...

result:

ok good!

Test #6:

score: 0
Accepted
time: 1578ms
memory: 134500kb

input:

10
33333 99999
60859 99999 1 60858
78724 99999 1 78723
42986 99999 1 42985
35108 99999 1 35107
63158 99999 1 63157
86977 99999 1 86976
13576 99999 1 13575
48277 99999 1 48276
89102 99999 1 89101
92657 99999 1 92656
25093 99999 1 25092
2353 99999 1 2352
81748 99999 1 81747
51216 99999 1 51215
75815 9...

output:

NIE
TAK
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

result:

ok good!