QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660326#9431. The Quest for El DoradoLateRegistration#RE 0ms0kbC++202.3kb2024-10-20 10:24:592024-10-20 10:24:59

Judging History

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

  • [2024-10-20 10:24:59]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-20 10:24:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

template <class comp = less<>> struct rmq {
	vector<vector<int>> st;
	rmq(const vector<int> &arr) : st(__lg(arr.size()) + 1) {
		st[0] = arr;
		for (int k = 1; k < st.size(); k++) {
			st[k] = st[k - 1];
			for (int i = 0; i + (1 << k) <= st[k].size(); i++) {
				int x = st[k - 1][i + (1 << (k - 1))];
				st[k][i] = comp()(st[k][i], x) ? st[k][i] : x;
			}
		}
	}

	int query(int l, int r) {
		int k = __lg(r - l + 1);
		int x = st[k][l], y = st[k][r - (1 << k) + 1];
		return comp()(x, y) ? x : y;
	}
};

void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<tuple<int, int, int>>> adj(n);
	for (int i = 0; i < m; i++) {
		int u, v, c, l;
		cin >> u >> v >> c >> l;
		u--, v--, c--;
		adj[u].emplace_back(v, c, l);
		adj[v].emplace_back(u, c, l);
	}
	vector<int> a(k), b(k);
	vector<vector<int>> pos(m);
	for (int i = 0; i < k; i++) {
		cin >> a[i] >> b[i];
		pos[--a[i]].push_back(i);
	}
	vector<rmq<greater<>>> rmq_b;
	for (int i = 0; i < m; i++) {
		vector<int> bs;
		for (int j : pos[i]) {
			bs.push_back(b[j]);
		}
		rmq_b.emplace_back(bs);
	}
	vector<array<int, 2>> dist(n, {k, 0});
	priority_queue<pair<array<int, 2>, int>, vector<pair<array<int, 2>, int>>, greater<>> pq;
	pq.emplace(dist[0] = {0, 0}, 0);
	while (!pq.empty()) {
		auto [d, u] = pq.top();
		pq.pop();
		if (d != dist[u]) continue;
		auto [id, used] = d;
		for (auto [v, c, l] : adj[u]) {
			if (a[id] != c || b[id] - used < l) {
				auto it = lower_bound(pos[c].begin(), pos[c].end(), id + 1);
				if (it != pos[c].end()) {
					int lb = pos[c].begin() - it, rb = pos[c].size() - 1, p = pos[c].size();
					while (lb <= rb) {
						int mid = (lb + rb) / 2;
						if (rmq_b[c].query(lb, mid) >= l) {
							rb = mid - 1;
							p = mid;
						} else {
							lb = mid + 1;
						}
					}
					if (p < pos[c].size()) {
						pq.emplace(dist[v] = {*it, p}, v);
					}
				}
			} else if (dist[v] > array{id, used + l}) {
				pq.emplace(dist[v] = {id, used + l}, v);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout.put(dist[i][0] == k ? '0' : '1');
	}
	cout << "\n";
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
5 6 4
1 2 1 30
2 3 1 50
2 5 5 50
3 4 6 10
2 4 5 30
2 5 1 40
1 70
6 100
5 40
1 30
3 1 1
2 3 1 10
1 100

output:


result: