| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1292479 | chaitanyamehta | Lost Array (NOI19_lostarray) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
struct DSU {
// ... (your DSU unchanged)
};
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int n, q;
cin >> n >> q;
DSU dsu;
dsu.init(n);
// Use map for sparse relations (keys are sorted pairs of roots)
map<pii, int> relations; // or unordered_map with hash for pii
while (q--) {
char t;
cin >> t;
int u, v;
cin >> u >> v;
int pu = dsu.find(u), pv = dsu.find(v);
if (t == 'Q') {
if (pu == pv) {
cout << "R\n";
} else {
pii key = {min(pu, pv), max(pu, pv)};
cout << (relations[key] ? "A\n" : "?\n");
}
} else if (t == 'A') {
if (pu != pv) { // Ignore if same
pii key = {min(pu, pv), max(pu, pv)};
relations[key] = 1;
}
} else { // 'C' - union
if (pu != pv) {
// TODO: Merge relations from pu and pv into new root
// E.g., iterate over current neighbors of pu/pv and add to new root
dsu.Union(u, v);
}
}
}
}
