QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586294#9319. Bull Farmxiao_xiaoWA 137ms35484kbC++204.9kb2024-09-24 10:31:362024-09-24 10:31:37

Judging History

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

  • [2024-09-24 10:31:37]
  • 评测
  • 测评结果:WA
  • 用时:137ms
  • 内存:35484kb
  • [2024-09-24 10:31:36]
  • 提交

answer

#include<bits/stdc++.h> 
#define ull unsigned long long
#define lch(x) t[x].s[0] 
#define rch(x) t[x].s[1]
#define INF 0x3f3f3f3f
#define ll long long 
#define lll __int128
#define re register
#define inl inline
#define N 1000050
#define rx x<<1|1
#define lx x<<1
using namespace std;

inline int read(){
	int w = 1 ,s = 0;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch=='-') w = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		s = (s<<3)+(s<<1)+ch-'0';
		ch = getchar();		
	}
	return w*s;
}

struct query{
	int time ,a ,b ,id ;
	bool operator<(const query&a) const{
		return time < a.time ;
	}
} ;

int cnt ,cnt1 ,top ,n ;
int scc[N] ,low[N] ,dfn[N] ,isstk[N] ,stk[N] ,ind[N] ;

bitset<2005> f[2005] ;

std::vector<int> v[2005] ,adj[2005] ;

int g[N] ,F[N] ;

int find(int x){
	if(x == g[x]) return x ;
	return g[x] = find(g[x]) ;
}

void tarjan(int x){
	dfn[x] = low[x] = ++ cnt ;
	isstk[x] = 1 ,stk[++top] = x ;
	for(auto v : adj[x]){
		if(!dfn[v]){
			tarjan(v) ;
			low[x] = min(low[x],low[v]) ;
		}
		else if(isstk[v]) low[x] = min(low[x],dfn[v]) ;
	}

	if(dfn[x] == low[x]){
		cnt1 ++ ;
		int y ;
		int p = find(x) ;
		do{
			y = stk[top--] ;
			g[find(y)] = p ;
			isstk[y] = false ;
		}while(y != x) ;
	}
}

void getpath(){
	for(int i = 1;i <= n;i ++ ) ind[i] = 0 ;
	for(int i = 1;i <= n;i ++ ){
		for(auto vv : adj[i]){
			if(find(vv) == find(i)) continue ;
			v[find(vv)].push_back(find(i)) ;
			ind[find(i)] ++ ; 
		}
	}
}

void toposort(){
	queue<int> q ;
	for(int i = 1;i <= n;i ++ ) if(!ind[i] && find(i) == i) q.push(i) ;
	while(!q.empty()){
		int x = q.front() ;
		q.pop() ;
		for(auto to : v[x]){
			f[to] |= f[x] ;
			if(!--ind[to]) q.push(to) ;
		}
	}
}

void solve(){
	int m ,q ;
	cin >> n >> m >> q ;
	std::vector<std::vector<int>> t(m+1) ;
	std::vector<int> num(n+1) ,anx(q) ;
	std::vector<query> Q(q) ;

	auto get = [&](){
		char s1 ,s2 ;
		cin >> s1 >> s2 ;
		int p1 = (s1 - 48) * 50 + s2 - 48 ;
		return p1 ;
	} ;

	for(int i = 1;i <= n;i ++ ){
		g[i] = i ;
		adj[i].clear() ;
	}
	for(int i = 1;i <= m;i ++ ){
		for(int j = 1;j <= n;j ++ ){
			int p = get() ;
			t[i].push_back(p) ;
		}
	}
	cnt = cnt1 = n ;
	for(int i = 1;i <= n;i ++ ) {
		f[i].reset() ;
		f[i][i] = 1 ;
		dfn[i] = 0 ;
		v[i].clear() ;
	}

	for(int i = 0;i < q;i ++ ) {
		int a = get() ,b = get() ,c = get() ;
		Q[i] = {c,a,b,i} ;
	}
	sort(Q.begin(),Q.end()) ;

	int time = 0 ;
	for(int i = 0;i < q;i ++ ){
		while(time + 1 <= m && time + 1 <= Q[i].time){
			time ++ ;
			for(int i = 1;i <= n;i ++ ) num[i] = F[i] = 0 ;
			for(auto val : t[time]) num[val] ++ ;
			std::vector<std::vector<int>> nadj(n+1) ;
			int sum = 0 ,px = 0 ;
			for(int i = 1;i <= n;i ++ ) {
				sum += !num[i] ;
				if(num[i] >= 2) px = i ;
			}
			if(!px){
				for(int i = 0;i < n;i ++ ){
					int to = t[time][i] ;
					if(find(i+1) != find(to)){
						adj[find(i+1)].push_back(find(to)) ;
					}
				}
			}
			else if(sum < 2) {
				int p = 0 ;
				for(int i = 0;i < n;i ++ ){
					if(!num[i+1]) p = i + 1 ;
				}
				if(p){
					for(int i = 0;i < n;i ++ ){
						if(t[time][i] == px && find(i+1) != find(p)){
							adj[find(i+1)].push_back(find(p)) ;
						}
					}
				}
			}
			//  int mul = -1, zero = -1, ok = 1;
			//   for (int j = 1; j <= n; ++j) {
	        //     if (num[j] == 2) {
	        //         if (mul == -1) mul = j;
	        //         else ok = 0;
	        //     }
	        //     if (num[j] == 0) {
	        //         if (zero == -1) zero = j;
	        //         else ok = 0;
	        //     }
        	// }
        	// if (!ok) continue;
        	//  if (mul == -1) {
	        //     for (int j = 1; j <= n; ++j) {
	        //         adj[find(j)].emplace_back(find(t[time][j-1]));
	        //     }
	        // }
	        // else if(ok) for (int j = 1; j <= n; ++j) {
	        //     if (num[t[time][j-1]] == 2) {
	        //        adj[find(j)].emplace_back(find(zero));
	        //     }
	        // }
			for(int i = 1;i <= n;i ++ ) dfn[i] = num[i] = low[i] = 0 ;
			cnt = cnt1 = top = 0 ;
			for(int i = 1;i <= n;i ++ ) if(!dfn[find(i)] && find(i) == i){
				tarjan(find(i)) ;
			}
			for(int i = 1;i <= n;i ++ ){
				int fa = find(i) ;
				for(auto to : adj[i]){
					int u = find(to) ;
					if(fa != u) nadj[fa].push_back(u) ;
				}
			}
			for(int i = 1;i <= n;i ++ ) {
				if(find(i) != i) continue ;
				nadj[i].erase(unique(nadj[i].begin(),nadj[i].end()),nadj[i].end()) ;
				adj[i] = nadj[i] ;
			}
			for(int i = 1;i <= n;i ++ ) v[i].clear() ,f[i].reset() ;
			getpath() ;
			for(int i = 1;i <= n;i ++ ) f[find(i)] |= 1 << find(i) ;
			toposort() ;
		}
		int a = find(Q[i].a) ,b = find(Q[i].b) ,c = Q[i].time ;
		anx[Q[i].id] = f[a][b] ;
		//cout << time << endl ;
	}
	for(int i = 0;i < q;i ++ ) cout << anx[i] ;
	cout << endl ;
}

int main(){
	ios::sync_with_stdio(false);
	
	int t ;
	cin >> t ;
	while(t -- )
	solve() ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 14108kb

input:

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

output:

010101

result:

ok single line: '010101'

Test #3:

score: 0
Accepted
time: 133ms
memory: 15968kb

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:

ok 200 lines

Test #4:

score: -100
Wrong Answer
time: 137ms
memory: 35484kb

input:

1
2000 1 1000000
M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...

output:

000101000101100010001000000010010110000001000001001100000000010000100001000000101100000000010000001000000001110000010110100000111100100000001000000000011001010001000001001000100000000100011001100110010000010000101100000011111000000010000101010010000000010101000001010111100000100000000000000101000100...

result:

wrong answer 1st lines differ - expected: '000101000101100010001000000010...0101000101000000000010101001000', found: '000101000101100010001000000010...0101000101000000000010101001000'