QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#218719#5504. Flower Gardengrass8cowAC ✓1959ms262164kbC++142.6kb2023-10-18 17:31:102023-10-18 17:31:12

Judging History

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

  • [2023-10-18 17:31:12]
  • 评测
  • 测评结果:AC
  • 用时:1959ms
  • 内存:262164kb
  • [2023-10-18 17:31:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,n_;
const int N=3e6+10,M=5e7+10;
int head[N],to[M],nxt[M],cn;
int dfn[N],low[N],sta[N],top,scc,col[N];
bool vis[N];
int ob[400100][2],os[N];
void ad(int u,int v){to[++cn]=v,nxt[cn]=head[u],head[u]=cn;}
void build(int p,int l,int r){
	if(l==r){ob[p][0]=ob[p][1]=l;return;}
	int mid=(l+r)>>1;build(p<<1,l,mid),build(p<<1|1,mid+1,r);
	ob[p][0]=++n_,head[n_]=0,ob[p][1]=++n_,head[n_]=0;
	ad(ob[p<<1][0],ob[p][0]),ad(ob[p<<1|1][0],ob[p][0]);
	ad(ob[p][1],ob[p<<1][1]),ad(ob[p][1],ob[p<<1|1][1]);
}
void dfs(int x){
	dfn[x]=low[x]=++dfn[0],sta[++top]=x,vis[x]=1;
	for(int i=head[x];i;i=nxt[i]){
		int v=to[i];
		if(!dfn[v])dfs(v),low[x]=min(low[x],low[v]);
		else if(vis[v])low[x]=min(low[x],dfn[v]);
	}
	if(dfn[x]==low[x]){
		scc++;
		while(sta[top]!=x)col[sta[top]]=scc,vis[sta[top]]=0,top--;
		col[x]=scc,vis[x]=0,top--;
	}
}
vector<int>fz;
#define pb push_back 
void as(int p,int l,int r,int x,int y){
	if(x<=l&&r<=y){fz.pb(p);return;}
	if(y<l||x>r)return;int mid=(l+r)>>1;
	as(p<<1,l,mid,x,y),as(p<<1|1,mid+1,r,x,y);
}
#define pb push_back
vector<int>g2[N],g[N];
int ru[N];
bool ans[N];
void print(){
	puts("TAK");
	for(int i=1;i<=n*3;i++)printf("%c",ans[col[i]]?'F':'R');
	puts("");
}
void sol(){
	cn=0,top=0,scc=0;
	scanf("%d",&n);n_=n*3;
	for(int i=1;i<=n_;i++)head[i]=0;
	build(1,1,n*3);
	int q;scanf("%d",&q);
	for(int i=1,a,b,c,d;i<=q;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);vector<int>p1,p2;
		fz.clear(),as(1,1,n*3,a,b),p1=fz;
		fz.clear(),as(1,1,n*3,c,d),p2=fz;
		head[++n_]=0;
		for(int x:p1)ad(ob[x][0],n_);
		for(int x:p2)ad(n_,ob[x][1]);
	}
	for(int i=0;i<=n_;i++)dfn[i]=low[i]=0;
	for(int i=1;i<=n_;i++)if(!dfn[i])dfs(i);
	for(int i=1;i<=scc;i++)os[i]=0,g[i].clear(),g2[i].clear(),ru[i]=0,ans[i]=0;
	for(int i=1;i<=n*3;i++)os[col[i]]++;
	for(int i=1;i<=n_;i++)for(int j=head[i];j;j=nxt[j])if(col[i]!=col[to[j]])
	g[col[i]].pb(col[to[j]]),g2[col[to[j]]].pb(col[i]),ru[col[i]]++;
	top=0;
	for(int i=1;i<=scc;i++)if(!ru[i])sta[++top]=i;
	vector<int>nd,S;int A=0;
	while(top){
		int u=sta[top--];
		if(os[u]>=n){S.pb(u);continue;}
		nd.pb(u),A+=os[u];
		for(int v:g2[u])if(!(--ru[v]))sta[++top]=v;
		if(A>=n)break;
	}
	if(A>=n){for(int x:nd)ans[x]=1;print();return;}
	for(int x:S){
		nd.clear();
		for(int i=1;i<=scc;i++)vis[i]=0;queue<int>q;q.push(x),vis[x]=1;
		A=0;
		while(!q.empty()){
			int u=q.front();q.pop();
			nd.pb(u),A+=os[u];
			for(int v:g[u])if(!vis[v])vis[v]=1,q.push(v);
		}
		if(A>=n&&A<=n*2){for(int x:nd)ans[x]=1;print();return;}
	}
	puts("NIE");
}
int main(){
	int T;cin>>T;while(T--)sol();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 165408kb

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: 1959ms
memory: 211500kb

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: 1658ms
memory: 245836kb

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: 1593ms
memory: 234468kb

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: 445ms
memory: 167496kb

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
RRRRRRRFRFFF
TAK
RFRFFFRRRRRR
NIE
TAK
RRRRRRRRFFFFFRR
TAK
RRRRRRRFRFFF
TAK
FFRRRRRRRRFF
TAK
RRRRRRFFFFFRRRR
TAK
RRRRRRRFRFFF
TAK
RRRRRRRRRRFFFFF
NIE
TAK
RRRFRRRRRFFF
NIE
TAK
RRFFFRRFF
NIE
TAK
RRRFFRRRF
TAK
RRRRRRRFRFFF
TAK
RRRRFRRRRRRFFFF
TAK
RRRRRRRFRFFF
NIE
TAK
...

result:

ok good!

Test #6:

score: 0
Accepted
time: 1395ms
memory: 262164kb

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!