QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#588461#9319. Bull Farm275307894a#WA 297ms18404kbC++143.4kb2024-09-25 11:48:002024-09-25 11:48:00

Judging History

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

  • [2024-09-25 11:48:00]
  • 评测
  • 测评结果:WA
  • 用时:297ms
  • 内存:18404kb
  • [2024-09-25 11:48:00]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e3+5,M=1e7+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,l,q;
int g[N],A[N],B[N];
int read(){
	char c=Gc();
	while(c<48||c>98) c=Gc();
	return (c-48)*50+Gc()-48;
}
vector<tuple<int,int,int>> Q[N];int ans[N*N];
int op[N],X[N],Y[N],Z[N],p[N][N],fa[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
vector<int> S[N],G[N];
int scc[N],cnt,in[N];
bitset<N> f[N];
namespace Tarjan{
	int dh,dfn[N],low[N],st[N],sh;
	void Tarjan(int x){
		dfn[x]=low[x]=++dh;st[++sh]=x;
		for(int i:S[x]){
			if(!dfn[i]) Tarjan(i),low[x]=min(low[x],low[i]);
			else if(!scc[i]) low[x]=min(low[x],dfn[i]);
		}
		if(dfn[x]==low[x]){
			++cnt;while(st[sh+1]^x) scc[st[sh]]=cnt,sh--;
		}
	}
	void build(){
		for(int i=1;i<=n;i++) dfn[i]=low[i]=scc[i]=st[i]=0;sh=dh=cnt=0;
		for(int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i);
	}
}
void Solve(){
	scanf("%d%d%d",&n,&l,&q);
	for(int i=1;i<=l;i++){
		Me(g,0);Me(B,-1);
		for(int j=1;j<=n;j++) A[j]=read(),g[A[j]]++;
		int cnt=0;
		for(int j=1;j<=n;j++) if(!g[j]) cnt++;
		int tot=0;
		for(int j=1;j<=n;j++) tot^=A[j]^j;
		for(int j=1;j<=n;j++){
			g[A[j]]--;
			if(!g[A[j]]) cnt++;
			if(cnt==1) B[j]=(tot^A[j]);
			if(!g[A[j]]) cnt--;
			g[A[j]]++;
		}
		cnt=count(B+1,B+n+1,-1);
		if(cnt==n) op[i]=0;
		else if(cnt==n-2){
			op[i]=1;X[i]=Y[i]=0;
			for(int j=1;j<=n;j++) if(~B[j]) (X[i]?Y[i]:X[i])=j,Z[i]=B[j];
		}else{
			op[i]=2;
			copy(B+1,B+n+1,p[i]+1);
		}
	}
	for(int i=1;i<=q;i++){
		int x=read(),y=read(),z=read();
		if(!z) ans[i]=(x==y);
		else Q[z].emplace_back(x,y,i);
	}
	iota(fa+1,fa+n+1,1);
	for(int i=1;i<=n;i++){
		if(op[i]==2){
			for(int j=1;j<=n;j++) fa[GF(j)]=GF(p[i][j]),gdb(j,p[i][j]);
		}
		for(int j=1;j<=n;j++) S[j].clear(),G[j].clear();
		for(int j=1;j<=i;j++) if(op[j]==1){
			S[GF(X[j])].push_back(GF(Z[j]));
			S[GF(Y[j])].push_back(GF(Z[j]));
			gdb(X[j],Z[j]);gdb(Y[j],Z[j]);
		}
		Tarjan::build(); 
		for(int j=1;j<=n;j++) for(int h:S[j]) if(scc[j]^scc[h]) G[scc[h]].push_back(scc[j]),in[scc[j]]++;
		for(int j=1;j<=cnt;j++) f[j].reset();
		for(int j=1;j<=n;j++) f[scc[GF(j)]].set(j);
		queue<int> q;
		for(int j=1;j<=cnt;j++) if(!in[j]) q.push(j);
		while(!q.empty()){
			int x=q.front();q.pop();
			for(int j:G[x]){
				if(!--in[j]) q.push(j);
				f[j]|=f[x];
			}
		}
		for(auto &[x,y,z]:Q[i]) ans[z]=f[scc[GF(x)]][y];
	}
	for(int i=1;i<=q;i++) printf("%d",ans[i]);
	printf("\n");
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1011
0100

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 8116kb

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: -100
Wrong Answer
time: 297ms
memory: 18404kb

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:

011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...

result:

wrong answer 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111111101111111111111111111...1111111111111110111111111111111'