QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470538#5504. Flower GardenyhdddWA 7804ms325772kbC++143.8kb2024-07-10 14:54:562024-07-10 14:54:57

Judging History

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

  • [2024-07-10 14:54:57]
  • 评测
  • 测评结果:WA
  • 用时:7804ms
  • 内存:325772kb
  • [2024-07-10 14:54:56]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
using namespace std;
const int maxn=1000010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m;
int head[maxn],tot;
vector<int> e[maxn];
#define mid (l+r>>1)
#define ls nd<<1
#define rs nd<<1|1
int in[maxn],out[maxn],idx;
void build(int nd,int l,int r){
	in[nd]=++idx;out[nd]=++idx;
	if(l==r){
		e[in[nd]].push_back(l),e[l].push_back(out[nd]);
		return ;
	}
	build(ls,l,mid),build(rs,mid+1,r);
	e[in[nd]].push_back(in[ls]),e[in[nd]].push_back(in[rs]);
	e[out[ls]].push_back(out[nd]),e[out[rs]].push_back(out[nd]);
}
void updin(int nd,int l,int r,int ql,int qr,int id){
	if(l>=ql&&r<=qr)return e[id].push_back(in[nd]);
	if(ql<=mid)updin(ls,l,mid,ql,qr,id);
	if(qr>mid)updin(rs,mid+1,r,ql,qr,id);
}
void updout(int nd,int l,int r,int ql,int qr,int id){
	if(l>=ql&&r<=qr)return e[out[nd]].push_back(id);
	if(ql<=mid)updout(ls,l,mid,ql,qr,id);
	if(qr>mid)updout(rs,mid+1,r,ql,qr,id);
}
int dfn[maxn],lw[maxn],cnt;
int scc[maxn],scct;
int st[maxn],tp;
vector<int> id[maxn];
void tar(int u){
	lw[u]=dfn[u]=++cnt;st[++tp]=u;
	for(int v:e[u]){
		if(!dfn[v]){
			tar(v);
			lw[u]=min(lw[u],lw[v]);
		}
		else if(!scc[v])lw[u]=min(lw[u],dfn[v]);
	}
	if(dfn[u]==lw[u]){
		++scct;
		scc[st[tp]]=scct;
		if(st[tp]<=3*n)id[scct].push_back(st[tp]);
		while(st[tp--]!=u){
			scc[st[tp]]=scct;
			if(st[tp]<=3*n)id[scct].push_back(st[tp]);
		}
	}
}
vector<int> g[maxn],gg[maxn];int d[maxn];
queue<int> q;
bool ans[maxn];
map<pii,bool> bk;
int sum[maxn];
void dfs(int u){
	for(int i:id[u])ans[i]=1;
	for(int v:g[u])dfs(v);
}
void work(){
	n=read();m=read();idx=3*n;
	build(1,1,3*n);
	while(m--){
		int a=read(),b=read(),c=read(),d=read();++idx;
		updin(1,1,3*n,c,d,idx),updout(1,1,3*n,a,b,idx);
	}
	for(int i=1;i<=idx;i++)if(!dfn[i])tar(i);
	for(int u=1;u<=idx;u++){
		for(int v:e[u]){
			if(scc[u]!=scc[v]&&!bk[{scc[u],scc[v]}]){
				// cout<<scc[u]<<" "<<scc[v]<<"\n";
				g[scc[u]].push_back(scc[v]),gg[scc[v]].push_back(scc[u]),d[scc[u]]++;
				bk[{scc[u],scc[v]}]=bk[{scc[v],scc[u]}]=1;
			}
		}
	}
	for(int i=1;i<=scct;i++)if(!d[i])q.push(i);
	int ss=0;bool fl=0;
	while(!q.empty()){
		int u=q.front();q.pop();ss+=id[u].size();
		// cout<<u<<" "<<ss<<"\n";
		for(int i:id[u])ans[i]=1;
		if(ss>=n)break;
		for(int v:gg[u]){
			if(!d[v])continue;
			d[v]--;if(!d[v])q.push(v);
		}
	}
	while(!q.empty())q.pop();
	if(ss<=2*n){
		puts("TAK");
		for(int i=1;i<=3*n;i++){if(ans[i])printf("F");else printf("R");}printf("\n");
	}
	else{
		for(int i=1;i<=n;i++)ans[i]=0;
		while(!q.empty()){
			int u=q.front();q.pop();sum[u]+=id[u].size();
			for(int v:gg[u]){
				if(!d[v])continue;
				d[v]--;sum[v]+=sum[u];if(!d[v])q.push(v);
			}
		}
		for(int u=1;u<=scct;u++)if(id[u].size()>=n&&id[u].size()<=2*n){
			if(sum[u]<=2*n){
				dfs(u);fl=1;
				break;
			}
			int ss=0;for(int v:g[u])ss+=sum[v];
			if(ss>=n){
				for(int v:g[u])dfs(v);fl=1;
				break;
			}
		}
		if(!fl)puts("NIE");
		else{
			puts("TAK");
			for(int i=1;i<=3*n;i++){if(ans[i])printf("F");else printf("R");}printf("\n");
		}
	}
	for(int i=1;i<=idx;i++)e[i].clear(),dfn[i]=scc[i]=0;
	for(int i=1;i<=scct;i++)g[i].clear(),gg[i].clear(),id[i].clear(),sum[i]=0;
	bk.clear();idx=scct=cnt=tp=0;
	for(int i=1;i<=3*n;i++)ans[i]=d[i]=0;
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=read();
	while(T--)work();
}

详细

Test #1:

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

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: 2029ms
memory: 243888kb

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: 7804ms
memory: 325772kb

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 odpowiedz ma za malo/duzo roz!