QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660327#9431. The Quest for El DoradoLateRegistration#TL 0ms3608kbC++202.3kb2024-10-20 10:25:542024-10-20 10:25:55

Judging History

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

  • [2024-10-20 10:25:55]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3608kb
  • [2024-10-20 10:25:54]
  • 提交

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) + 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: 100
Accepted
time: 0ms
memory: 3608kb

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:

11011
100

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

1110
46 80 30
44 23 5 46
10 28 1 64
32 34 3 40
9 36 1 26
15 14 5 95
38 19 2 34
2 17 4 183
10 38 2 81
5 15 2 83
31 38 3 100
40 30 1 53
41 10 1 193
29 20 5 18
14 41 3 78
8 16 5 74
46 13 3 78
44 28 3 45
1 40 3 133
5 32 1 108
22 26 2 83
10 38 1 77
11 40 1 11
17 21 2 66
41 46 3 98
9 36 2 25
40 18 1 19
27...

output:

1111000110110111110110111010110011111111110110
1000000010001001011011000000001000000100000000
1000000000000000000000000000000000000000000000
1111010000000010000100010011000100000000100010
1111100100110010100100101100111101101011001111
1001100010110000100001100000100011001110110
100010000000000000000...

result: