QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#585551#9319. Bull Farmxiao_xiaoTL 438ms18188kbC++205.2kb2024-09-23 21:12:282024-09-23 21:12:29

Judging History

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

  • [2024-09-23 21:12:29]
  • 评测
  • 测评结果:TL
  • 用时:438ms
  • 内存:18188kb
  • [2024-09-23 21:12:28]
  • 提交

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] ;

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 ;
		do{
			y = stk[top--] ;
			g[y] = x ;
			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 ++ ){
		if(find(i) != i) continue ;
		for(auto vv : adj[i]){
			if(scc[vv] == scc[i] || find(vv) != vv) 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 ;
	}
	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 ;
		scc[i] = i ;
		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] = 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 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] = 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(g[i] != g[u]) nadj[g[i]].push_back(g[u]) ;
				}
			}
			for(int i = 1;i <= n;i ++ ) {
				sort(nadj[i].begin(),nadj[i].end()) ,nadj[i].erase(unique(nadj[i].begin(),nadj[i].end()),nadj[i].end()) ,adj[i] = nadj[i] ;
				int u = find(i) ,v = find(g[i]) ;
				f[u] = v ;
			}
		}
		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 << i ;
		toposort() ;
		int a = find(Q[i].a) ,b = Q[i].b ,c = Q[i].time ;
		// for(int i = 1;i <= cnt1;i ++ ) {
		// 	for(int j = 1;j <= n;j ++ )cout << f[i][j] ;
		// 	cout << endl ;
		// }
		// cout << a << ' ' << b << ' ' << c << endl ;
		anx[Q[i].id] = f[a][b] ;
		//cout << time << endl ;
	}
	for(int i = 0;i < q;i ++ ) cout << anx[i] ;
	//cout << endl ;

	cout << endl ;
}

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

详细

Test #1:

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

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: 0ms
memory: 16152kb

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: 438ms
memory: 15920kb

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
Time Limit Exceeded

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:


result: