QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#393034#6330. XOR ReachableGiga_Cronos#RE 0ms3924kbC++232.9kb2024-04-18 04:35:352024-04-18 04:35:35

Judging History

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

  • [2024-04-18 04:35:35]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3924kb
  • [2024-04-18 04:35:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define MAXN   ((ll)(1e5 + 5))
#define all(x) (x).begin(), (x).end()
const ll mod = 998244353;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct dsu {
	vector<ll> d;
	ll ans;
	struct info {
		int u, v;
		int pdu, pdv;
		int pans;
	};
	vector<info> undoing;

	dsu(int n) {
		d.resize(n);
		for (int i = 0; i < n; i++)
			d[i] = -1;
		ans = 0;
		undoing = {};
	}

	void undo() {
		assert(!undoing.empty());
		info x = undoing.back();
		undoing.pop_back();
		if (x.u == -1)
			return;
		d[x.u] = x.pdu;
		d[x.v] = x.pdv;
		ans = x.pans;
	}

	int find(int u) {
		if (d[u] < 0)
			return u;
		return find(d[u]);
	}

	void join(int u, int v) {
		u = find(u);
		v = find(v);
		if (u == v) {
			undoing.push_back({-1, -1, -1, -1, -1});
			return;
		}
		if (d[u] > d[v])
			swap(u, v);
		undoing.push_back({u, v, d[u], d[v], ans});

		ans += d[u] * d[v];
		// cout << u << ' ' << v << "\n";
		// cout << ans << ' ' << d[u] << ' ' << d[v] << '\n';
		d[u] += d[v];
		d[v] = u;
	}
};

struct edge {
	int u, v;
	int type;
	int lim, len;
};

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, m, k;
	cin >> n >> m >> k;
	vector<int> dec;
	for (int i = 0; i < 30; i++)
		if (k & (1 << i))
			dec.push_back(1 << i);
	reverse(all(dec));
	vector<edge> ts;
	for (int i = 0; i < m; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		u--, v--;
		int act = 0;
		// cout << "\n";
		// cout << i << "\n";
		for (int j = 0; j < dec.size(); j++) {
			int x = (c - (c & (dec[j] - 1))) ^ act;
			ts.push_back({u, v, +1, x, dec[j]});
			ts.push_back({u, v, -1, x + dec[j], dec[j]});
			// cout << x << ' ' << x + dec[j] << "\n";
			act |= dec[j];
		}
	}

	sort(all(ts), [&](edge &e1, edge &e2) {
		if (e1.lim != e2.lim) {
			return e1.lim < e2.lim;
		}
		if (e1.type != e2.type) {
			return e1.type < e2.type;
		}
		if (e1.len != e2.len) {
			if (e1.type == +1) {
				return e1.len > e2.len;
			}
			return e1.len < e2.len;
		}
		return true;
	});

	// for (int i = 0; i < ts.size(); i++) {
	// 	cout << ts[i].u << ' ' << ts[i].v << ' ' << ts[i].type << ' '
	// 	     << ts[i].lim << ' ' << ts[i].len << '\n';
	// }

	int q;
	cin >> q;
	vector<pii> tsq;
	for (int i = 0; i < q; i++) {
		int d;
		cin >> d;
		tsq.push_back(pii(d, i));
	}

	sort(all(tsq));

	vector<ll> ans(q);
	dsu ds(n);
	int pos = 0;
	for (int i = 0; i < q; i++) {
		int t = tsq[i].first;
		int id = tsq[i].second;
		// cout << id << '\n';
		while (pos < ts.size() && ts[pos].lim <= t) {
			if (ts[pos].type == +1) {
				// cout << ts[pos].u << ' ' << ts[pos].v << "\n";
				ds.join(ts[pos].u, ts[pos].v);
			} else
				ds.undo();
			pos++;
		}
		ans[id] = ds.ans;
	}

	for (int i = 0; i < q; i++)
		cout << ans[i] << "\n";

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5 5
1 2 17
1 3 4
2 3 20
2 4 3
3 4 5
4
0
7
16
167

output:

2
6
3
0

result:

ok 4 number(s): "2 6 3 0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

9 13 488888932
2 7 771479959
3 8 783850182
5 7 430673756
6 8 350738034
4 9 400768807
2 3 83653266
1 2 829786563
5 8 357613791
7 9 579696618
3 7 423191200
3 5 867380255
1 9 907715012
6 9 1033650694
8
498260055
144262908
117665696
848664012
983408133
32610599
478007408
134182829

output:

16
7
5
13
13
16
16
5

result:

ok 8 numbers

Test #3:

score: -100
Runtime Error

input:

446 99235 764320136
1 2 467639025
1 39 240791819
1 197 320023434
1 391 968343602
1 116 841220144
1 345 697806443
1 409 489643820
1 339 733516272
1 89 560099922
1 431 722346703
1 433 246809211
1 344 769002876
1 234 597076758
1 178 505730391
1 75 826728597
1 74 14756981
1 63 280238017
1 288 638627144
...

output:


result: