QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#456871#7103. Red Black Treeucup-team3282Compile Error//C++143.1kb2024-06-28 16:15:372024-06-28 16:15:38

Judging History

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

  • [2024-06-28 16:15:38]
  • 评测
  • [2024-06-28 16:15:37]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
const int N = 2e5+9;
int fa[N][21], dep[N], dis[N], n, m, q, r[N], isred[N], anc[N], nr = 1, node[N], k, tot, dfn[N], LG[N], st[N][21], rev[N][21], pos[N], cnt;
vector<pair<int, int>> adj[N];
void dfs1(int u, int f, int d) {
	fa[u][0] = f; dfn[++tot] = u; dep[tot] = d; pos[u] = tot;
	if (!isred[u]) anc[u] = nr;
	int tmp = nr;
	for (auto i : adj[u]) {
		if (i.fi == f) continue;
		if (isred[i.fi]) nr = i.fi;
		dis[i.fi] = dis[u] + i.se;
		dfs1(i.fi, u, d + 1);
        dfn[++tot] = u; dep[tot] = d;
	}
	
	nr = tmp;
}

void init() {
    for (int i = 2; i <= tot; i++) LG[i] = LG[i >> 1] + 1;
    for (int i = 1; i <= tot; i++) {
        st[i][0] = dep[i];
        rev[i][0] = dfn[i];
    }

    for (int j = 1; j <= LG[tot]; j++) {
        for (int i = 1; i + (1 << j) - 1 <= tot; i++) {
            if (st[i][j - 1] < st[i + (1 << (j - 1))][j - 1]) st[i][j] = st[i][j - 1], rev[i][j] = rev[i][j - 1];
            else st[i][j] = st[i + (1 << (j - 1))][j - 1], rev[i][j] = rev[i + (1 << (j - 1))][j - 1];
        }
    }
}

int query(int l, int r) {
	int k = LG[r - l + 1];
    return st[l][k] < st[r - (1 << k) + 1][k] ? rev[l][k] : rev[r - (1 << k) + 1][k];
}

int lca(int x, int y) {
    if (pos[x] > pos[y]) swap(x, y);
    return query(pos[x], pos[y]);
}

bool check(int lim) {
	int cc = 0;
	for (int i = 1; i <= k; i++) {
		int u = node[i];
		if (dis[u] - dis[anc[u]] <= lim) continue;
		cc++;
	}
	
	if (cc == 0) return true;
	int zx = 0;
	for (int i = 1; i <= k; i++) {
		int u = node[i];
		if (dis[u] - dis[anc[u]] > lim) {
			if (!zx) {
                zx = u;
                continue;
            }

			zx = lca(zx, u);
		}
	}
	
	int mx = -1;
	for (int i = 1; i <= k; i++) {
		int u = node[i];
		if (dis[u] - dis[anc[u]] > lim) {
			mx = max(mx, dis[u]);
		}
	}
	
	return mx - dis[zx] <= lim;
}

void solve() {
	cin >> n >> m >> q;
	memset(dis, 0, sizeof(int) * (2 * n + 9));
	memset(isred, 0, sizeof(int) * (2 * n + 9));
	memset(dep, 0, sizeof(int) * (2 * n + 9));
	memset(anc, 0, sizeof(int) * (2 * n + 9));
    memset(pos, 0, sizeof(int) * (2 * n + 9));
    memset(dfn, 0, sizeof(int) * (2 * n + 9));
	nr = 1;
	for (int i = 0; i <= n; i++) adj[i].clear();
	for (int i = 1; i <= m; i++) {
		cin >> r[i];
		isred[r[i]] = true;
		anc[r[i]] = r[i];
	}
	
	for (int i = 1, u, v, w; i < n; i++) {
		cin >> u >> v >> w;
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}

    tot = 0;
	
	dfs1(1, 0, 1);
    init();
	
	while (q--) {
        cnt++;
		cin >> k;
		for (int i = 1; i <= k; i++) {
			cin >> node[i];
		}
		
		int l = 0, r = 1e16, ans = 0;
		while (l <= r) {
			int mid = (l + r) >> 1;
            if (cnt == 18) cout << mid << endl;
			if (check(mid)) {
				ans = mid;
				r = mid - 1;
			} else l = mid + 1;
		}
		
		if (cnt == 18) cout << ans << "\n";
	}
}

signed main() {
	//freopen("B.in", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T; cin >> T;
	while (T--) {
		solve();
	}
	
	return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:118:46: error: unable to find numeric literal operator ‘operator"";’
  118 |                         int mid = (l + r) >> 1;
      |                                              ^~~
answer.code:118:46: note: use ‘-fext-numeric-literals’ to enable more built-in suffixes