QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#602728#8716. 树UESTC_DebugSimulator#Compile Error//C++172.5kb2024-10-01 12:28:192024-10-01 12:28:19

Judging History

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

  • [2024-10-01 12:28:19]
  • 评测
  • [2024-10-01 12:28:19]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(i) (i&-i)
#define rand() (myrand())
using namespace std;
mt19937 myrand(time(0));
const int maxn = 2e5 + 5;
int n, _, m, q, fa[maxn][20], head[maxn], cnt, b[maxn], dep[maxn], c[maxn];
struct EDGE{
	int next, to;
}edge[maxn<<1];
void addedge(int from, int to) {
	edge[++cnt].next = head[from];
	edge[cnt].to = to;
	head[from] = cnt;
}
void dfs(int u, int p) {
	fa[u][0] = p;
	dep[u] = dep[p] + 1;
	for (int i = head[u] ; i ; i = edge[i].next) {
		int v = edge[i].to;
		if (v == p) continue;
		dfs(v, u);
	} 
}
int check(int u, int v) {
	if (dep[v] > dep[u]) {
		int k = dep[v] - dep[u];
		for (int i = 19 ; i >= 0 ; --i) {
			if (k&(1<<i)) v = fa[v][i];
		}
		if (v != u) return 2;
		return 0;
	}
	else {
		int k = dep[u] - dep[v];
		for (int i = 19 ; i >= 0 ; --i) {
			if (k&(1<<i)) u = fa[u][i];
		}
		if (v != u) return 2;
		return 1;
	}
}
int get(int x, int y) {
	if (x == y) return x == 2;
	if ((x == 1 && y == 0) && (x == 0 && y == 1)) return 1;
	if (x == 2) {
		if (y == 0) return 0;
		return 1;
	}
	if (y == 2) {
		if (x == 0) return 1;
		return 0;
	}
}
void solve() {
	cin >> n >> m >> q;
	for (int i = 1 ; i < n ; ++i) {
		int u, v;
		cin >> u >> v;
		addedge(u, v);
		addedge(v, u);
	}
	dfs(1, 0);
	for (int j = 1 ; j < 20 ; ++j) {
		for (int i = 1 ; i <= n ; ++i) fa[i][j] = fa[fa[i][j - 1]][j - 1];
	}
	for (int i = 1 ; i <= m ; ++i) cin >> b[i];
	if (m == 1) {
		for (int i = 1 ; i <= q ; ++i) {
			int p, w;
			cin >> p >> w;
			cout << 1 << '\n';
		}
		return;
	}
	int ans = 2;
	c[1] = check(b[1], b[2]);
	for (int i = 3 ; i <= m ; ++i) {
		c[i - 1] = check(b[i - 1], b[i]);
		ans += get(c[i - 2], c[i - 1]);
	}
	for (int i = 1 ; i <= q ; ++i) {
		int p, w;
		cin >> p >> w;
		b[p] = w;
		if (p == 1) {
			ans -= get(c[p], c[p + 1]);
			c[p] = check(b[p], b[p + 1]);
			ans += get(c[p], c[p + 1]);
		}
		else if (p == n) {
			ans -= get(c[p - 2], c[p - 1]);
			c[p - 1] = check(b[p - 1], b[p]);
			ans += get(c[p - 2], c[p - 1]);
		}
		else { ans -= get(c[p - 2], c[p - 1]);
			c[p - 1
			if (p >= 3)] = check(b[p - 1], b[p]);
			if (p >= 3) ans += get(c[p - 2], c[p - 1]);
			
			if (p <= n - 2) ans -= get(c[p], c[p + 1]);
			c[p] = check(b[p], b[p + 1]);
			if (p <= n - 2) ans += get(c[p], c[p + 1]);
		}
		cout << ans << '\n';
	}
}
signed main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:99:32: error: expected ‘]’ before ‘if’
   99 |                         c[p - 1
      |                                ^
      |                                ]
  100 |                         if (p >= 3)] = check(b[p - 1], b[p]);
      |                         ~~      
answer.code:99:32: error: expected ‘;’ before ‘if’
   99 |                         c[p - 1
      |                                ^
      |                                ;
  100 |                         if (p >= 3)] = check(b[p - 1], b[p]);
      |                         ~~      
answer.code: In function ‘int get(int, int)’:
answer.code:56:1: warning: control reaches end of non-void function [-Wreturn-type]
   56 | }
      | ^