QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#77800#5504. Flower GardenchenshiWA 2483ms71312kbC++2.6kb2023-02-15 17:04:072023-02-15 17:04:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-15 17:04:10]
  • 评测
  • 测评结果:WA
  • 用时:2483ms
  • 内存:71312kb
  • [2023-02-15 17:04:07]
  • 提交

answer

#include<cstdio>
#include<queue>
#include<iostream>
using namespace std;
const int o=8e5,O=2e7;
int z,n,q,ls[o],rs[o],rt1,rt2,tot,h[o],cnt,dfn[o],low[o],st[o],tp,H[o],Cnt,sccn,scc[o],s[o],d[o],topo[o],num;
bool vis[o],vio[o];bool flg;queue<int> Q;
struct Edge{int v,p;}e[O],E[O];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
inline void Ad(int U,int V){++d[E[++Cnt].v=V];E[Cnt].p=H[U];H[U]=Cnt;}
void build1(int&id,int l,int r){
	if(l==r){id=l;return;}
	id=++tot;
	int md=l+r>>1;
	build1(ls[id],l,md);build1(rs[id],md+1,r);
	ad(ls[id],id);ad(rs[id],id);
}
void build2(int&id,int l,int r){
	if(l==r){id=r;return;}
	id=++tot;
	int md=l+r>>1;
	build2(ls[id],l,md);build2(rs[id],md+1,r);
	ad(id,ls[id]);ad(id,rs[id]);
}
void modify1(int id,int ql,int qr,int val,int l=1,int r=n*3){
	if(ql<=l&&r<=qr){ad(id,val);return;}
	int md=l+r>>1;
	if(ql<=md) modify1(ls[id],ql,qr,val,l,md);
	if(md<qr) modify1(rs[id],ql,qr,val,md+1,r);
}
void modify2(int id,int ql,int qr,int val,int l=1,int r=n*3){
	if(ql<=l&&r<=qr){ad(val,id);return;}
	int md=l+r>>1;
	if(ql<=md) modify2(ls[id],ql,qr,val,l,md);
	if(md<qr) modify2(rs[id],ql,qr,val,md+1,r);
}
void tarjan(int nw){
	dfn[nw]=low[nw]=++cnt;vis[st[++tp]=nw]=1;
	for(int i=h[nw];i;i=e[i].p)
		if(!dfn[e[i].v]) tarjan(e[i].v),low[nw]=min(low[nw],low[e[i].v]);
		else if(vis[e[i].v]) low[nw]=min(low[nw],dfn[e[i].v]);
	if(dfn[nw]==low[nw]) for(++sccn,st[tp+1]=0;st[tp+1]^nw;vis[st[tp--]]=0) s[scc[st[tp]]=sccn]+=(st[tp]<=n*3);
}
int main(){
	for(scanf("%d",&z);z--;putchar('\n'),cnt=Cnt=sccn=flg=0){
		scanf("%d%d",&n,&q);tot=n*3;
		build1(rt1,1,n*3);build2(rt2,1,n*3);
		for(int a,b,c,d;q--;) scanf("%d%d%d%d",&a,&b,&c,&d),modify1(rt1,a,b,++tot),ad(tot,tot+1),modify2(rt2,c,d,++tot);
		for(int i=1;i<=tot;++i) if(!dfn[i]) tarjan(i);
		for(int i=1;i<=tot;++i) for(int j=h[i];j;j=e[j].p) if(scc[i]^scc[e[j].v]) Ad(scc[i],scc[e[j].v]);
		for(int i=1;i<=sccn;++i) if(!d[i]) Q.push(i);
		for(int t=0;!Q.empty();topo[++t]=Q.front(),Q.pop())
			for(int i=H[Q.front()];i;i=E[i].p) if(!--d[E[i].v]) Q.push(E[i].v);
		for(int i=sccn,t=0;i;--i) if((t+=s[topo[i]])>=n)
			if(t<=n*2){flg=1;for(int j=i;j<=sccn;++j) vio[topo[j]]=1;break;}
			else{Q.push(topo[i]);vio[topo[i]]=1;break;}
		if(!flg){
			for(num=0;!Q.empty();num+=s[Q.front()],Q.pop())
				for(int i=H[Q.front()];i;i=E[i].p) if(!vio[E[i].v]) vio[E[i].v]=1,Q.push(E[i].v);
			flg=(num<=n*2);
		}
		if(flg){
			printf("TAK\n");
			for(int i=1;i<=n*3;++i) putchar(vio[scc[i]]?'F':'R');
		}
		else printf("NIE");
		for(int i=1;i<=tot;++i) h[i]=dfn[i]=0;
		for(int i=1;i<=sccn;++i) H[i]=s[i]=vio[i]=0;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 20036kb

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: 2483ms
memory: 71312kb

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: 1672ms
memory: 63492kb

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: 1607ms
memory: 59648kb

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: -100
Wrong Answer
time: 507ms
memory: 20116kb

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
RRRRRRFFRFFR
TAK
RFRFFFRRRRRR
NIE
TAK
RRRRRRRFFFFFRRR
TAK
RRRRRRFFRFFR
TAK
FFRRRRRRRRFF
TAK
FFFFRRRRRFRRRRR
TAK
RRRRRRFFRFFR
TAK
RRRRRRRRRFFFFFR
NIE
TAK
RRRFRRRRRFFF
NIE
TAK
RRFFFRRFF
NIE
TAK
FFRRFRRRR
TAK
RRRRRRFFRFFR
TAK
RRFFRFRFFFFFRFF
TAK
RRRRRRFFRFFR
NIE
TAK
...

result:

wrong answer zla odpowiedz!