QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#578249 | #6679. Not Another Path Query Problem | shiqiaqiaya# | TL | 1ms | 3848kb | C++17 | 2.1kb | 2024-09-20 17:42:45 | 2024-09-20 17:42:47 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
mt19937_64 rd(time(0));
template <class key, class val = null_type, class cmp = less<>>
using rb_tree = tree<key, val, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A>
void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const int N = 1e5 + 10;
int fa[N];
int find(int x) {
return fa[x] = fa[x] == x ? x : find(fa[x]);
}
void QAQ() {
int n, m, q , V;
cin >> n >> m >> q >> V;
for (int i = 1; i <= n; i++) {
fa[i] = i;
}
vector<array<int, 3>> e(m);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
e[i] = {w, u, v};
}
vector<array<int, 3>> Q(q);
vector<int> ans(q);
for (int i = 0; i < q; i++) {
int u, v;
cin >> u >> v;
Q[i] = {u, v, i};
}
int l = 0, r = n;
int j = 60;
while ((V >> j) == 0) j--;
for (; j >= 0; j--) {
int v = (V >> j) & 1;
// cerr << j << " " << v << " " << l << " " << r << "\n";
if (v == 0) {
for (int i = l; i < r; i++) {
int u = e[i][1], v = e[i][2];
u = find(u), v = find(v);
if (u == v) continue;
fa[u] = v;
}
for (auto [u, v, i] : Q) {
ans[i] |= find(u) == find(v);
}
l = r;
r = n;
} else {
int mid = partition(e.begin() + l, e.begin() + r, [&](auto x) {
return (x[0] >> j) & 1;
}) - e.begin();
r = mid;
}
}
for (int i = 0; i < q; i++) {
cout << (ans[i] ? "Yes" : "No") << "\n";
}
}
signed main() {
int t = 1;
//cin >> t;
for (cin.tie(0) -> sync_with_stdio(0), cout << fixed << setprecision(12); t--; QAQ());
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
9 8 4 5 1 2 8 1 3 7 2 4 1 3 4 14 2 5 9 4 5 7 5 6 6 3 7 15 1 6 2 7 7 6 1 8
output:
Yes No Yes No
result:
ok 4 token(s): yes count is 2, no count is 2
Test #2:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
3 4 1 4 1 2 3 1 2 5 2 3 2 2 3 6 1 3
output:
Yes
result:
ok YES
Test #3:
score: -100
Time Limit Exceeded
input:
100 2000 50000 0 32 52 69658009083393280 26 38 868250171554967916 87 32 743903879320440454 22 15 19782587273744714 57 98 845866434191429143 42 95 1145336983294966993 67 40 1036117659380117375 46 24 265457274847122243 63 44 438254608190938148 28 23 992625102587165494 57 87 558124114385470345 6 17 535...