QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565108#9319. Bull FarmlimpidCompile Error//C++144.5kb2024-09-15 20:17:122024-09-15 20:17:14

Judging History

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

  • [2024-09-15 20:17:14]
  • 评测
  • [2024-09-15 20:17:12]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
using namespace std;
inline int read(){
	int f = 1, ans = 0;
	char c = getchar();
	while(c < '0' || c > '9'){if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ans = ans * 10 + c - '0'; c = getchar();}
	return f * ans;
}
const int MAXN = 2e3 + 11;
int cas, N, L, Q;
struct Union{
	int f[MAXN];
	void Init(){
		for(int i = 1; i <= N; i++) f[i] = i;
		return;
	}
	int find(int x){return f[x] == x ? x : f[x] = find(f[x]);}
	void merge(int x, int y){
		int t1 = find(x), t2 = find(y);
		f[t2] = t1;
		return;
	}
}U;
char str[MAXN * 2];
int A[MAXN][MAXN];
struct Que{
	int A, B, C, id;
}Query[MAXN];
bool cmp(Que w1, Que w2){
	return w1.C < w2.C;
}
int buc[MAXN], vis[MAXN];
vector<pii> vec;
void Press(int tim){
	for(int i = 1; i <= N; i++) buc[i] = 0;
	for(int i = 1; i <= N; i++) buc[A[tim][i]]++;
	bool flag = 1;
	for(int i = 1; i <= N; i++) flag &= (buc[i] == 1);
	if(flag){
		for(int i = 1; i <= N; i++) U.merge(A[tim][i], i);
		return;
	}
	int cnt = 0;
	for(int i = 1; i <= N; i++) cnt += (buc[i] >= 2);
	if(cnt > 1) return;
	for(int i = 1; i <= N; i++) if(buc[i] > 2) return;
	int pos = -1;
	for(int i = 1; i <= N; i++) if(buc[i] == 2) pos = i;
	int pos1 = -1;
	for(int i = 1; i <= N; i++) if(buc[i] == 0) pos1 = i; 
	assert(cnt == 1);
	for(int i = 1; i <= N; i++) if(A[tim][i] == pos) vec.pb(mp(i, pos1));
	return;
}
int dfn[MAXN], low[MAXN], num, tot1, col[MAXN], sta[MAXN];
vector<int> vec1[MAXN];
void tarjan(int u){
	dfn[u] = low[u] = ++num;
	sta[++tot1] = u;
	for(auto v:vec1[u]){
		if(!dfn[v]){
			tarjan(v);
			low[u] = min(low[u], low[v]);
			continue;
		}else if(!col[v]) low[u] = min(low[u], dfn[v]);
	}
	if(low[u] == dfn[u]){
		col[u] = ++col[0];
		while(sta[tot1] != u){
			col[sta[tot1]] = col[0];
			tot1--;
		}tot1--;
	}return;
}
void Clear1(){
	col[0] = 0;
	for(int i = 1; i <= N; i++) dfn[i] = low[i] = num = tot1 = col[i] = 0, vec1[i].clear();
	return;
}
bitset<MAXN> G[MAXN];
vector<int> vec2[MAXN];
int deg[MAXN];
queue<int> Queu;
bool Ans[MAXN];
int main(){
//	freopen("1.in", "r", stdin);
	cas = read();
	while(cas--){
		N = read(), L = read(),Q = read(); U.Init();
		vec.clear();
		for(int i = 1; i <= L; i++){
			scanf("%s", str + 1);
			for(int j = 1; j <= N; j++){
				int c1 = str[2 * j - 1] - '0', c2 = str[2 * j] - '0';
				int w = c1 * 50 + c2;
				A[i][j] = w;
			}
		}
		for(int i = 1; i <= Q; i++){
			Query[i].id = i;
			scanf("%s", str + 1);
			int c1 = str[1] - '0', c2 = str[2] - '0';
			int A = c1 * 50 + c2;
			c1 = str[3] - '0', c2 = str[4] - '0';
			int B = c1 * 50 + c2;
			c1 = str[5] - '0', c2 = str[6] - '0';
			int C = c1 * 50 + c2;
			Query[i].A = A, Query[i].B = B, Query[i].C = C; 
//			cerr<<A<<" "<<B<<" "<<C<<endl;
		} 
		sort(Query + 1, Query + Q + 1, cmp);
		int pp = 1;
		for(int i = 0; i <= L; i++){
			Clear1();
			for(auto pr: vec){
				vec1[U.find(pr.fi)].pb(U.find(pr.se));
			}
//			for(int j = 1; j <)
			for(int j = 1; j <= N; j++) if(U.find(j) == j && !dfn[j]) tarjan(j);
//			for(int j = 1; j <= N; j++) cerr << col[j] << " "; cerr << endl;
//			for(int i = 1; i <= N; i++) cerr << U.find(i) << " "; cerr << endl; 
//			for(int j = 1; j <= N; j++) if(U.find(j) == j) G[col[j]][j] = 1;
			for(int j = 1; j <= col[0]; j++) G[j][j] = 1; 
			for(int j = 1; j <= col[0]; j++) vec2[j].clear(), deg[j] = 0;
//			cerr << col[0] << endl;
			
			for(auto pr: vec){
				int u = U.find(pr.fi), v = U.find(pr.se);
				if(col[u] == col[v]) continue;
				u = col[u], v = col[v];
				vec2[v].pb(u), deg[u]++;
			}
			for(int j = 1; j <= col[0]; j++) if(!deg[j]) Queu.push(j);
			while(!Queu.empty()){
				int x = Queu.front(); Queu.pop();
				for(auto v:vec2[x]){
					deg[v]--;
					G[v] |= G[x];
					if(!deg[v]) Queu.push(v);
				}
			}
//			cerr<<"i:"<<i<<endl;
			while(pp <= Q && Query[pp].C == i){
				int a = U.find(Query[pp].A), b = U.find(Query[pp].B), c = Query[pp].C, id = Query[pp].id;
				a = col[a], b = col[b];
				//cerr<<"Ua:"<<U.find(Query[pp].A)<<" Ub:"<<U.find(Query[pp].B)<<" "<<col[1]<<" "<<col[2]<<endl;
				//cerr<<"a:"<<a<<" b:"<<b<<" pp:"<<pp<<" Q:"<<Q<<" "<<Query[pp + 1].C<<" "<<i<<endl;
				Ans[id] = G[a][b];
				pp++;
			}
			if(i != L) Press(i + 1);
		}
		for(int i = 1; i <= Q; i++) printf("%d", Ans[i]); printf("\n");
	}
}


Details

answer.code: In function ‘void Press(int)’:
answer.code:62:9: error: ‘assert’ was not declared in this scope
   62 |         assert(cnt == 1);
      |         ^~~~~~
answer.code:7:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
    6 | #include<queue>
  +++ |+#include <cassert>
    7 | #define fi first
answer.code: At global scope:
answer.code:91:1: error: ‘bitset’ does not name a type
   91 | bitset<MAXN> G[MAXN];
      | ^~~~~~
answer.code: In function ‘int main()’:
answer.code:134:58: error: ‘G’ was not declared in this scope
  134 |                         for(int j = 1; j <= col[0]; j++) G[j][j] = 1;
      |                                                          ^
answer.code:149:41: error: ‘G’ was not declared in this scope
  149 |                                         G[v] |= G[x];
      |                                         ^
answer.code:159:43: error: ‘G’ was not declared in this scope
  159 |                                 Ans[id] = G[a][b];
      |                                           ^
answer.code:103:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  103 |                         scanf("%s", str + 1);
      |                         ~~~~~^~~~~~~~~~~~~~~
answer.code:112:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  112 |                         scanf("%s", str + 1);
      |                         ~~~~~^~~~~~~~~~~~~~~