# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40398 | szawinis | Pictionary (COCI18_pictionary) | C++14 | 430 ms | 27188 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+2;
int n, m, q, a[N], b[N], l[N], r[N], dsu[N];
vector<int> ls[N];
int root(int v) { return (dsu[v] < 0 ? v : dsu[v] = root(dsu[v])); }
void merge(int u, int v) {
if((u = root(u)) == (v = root(v))) return;
if(dsu[u] > dsu[v]) swap(u, v);
dsu[u] += dsu[v];
dsu[v] = u;
}
int main() {
scanf("%d %d %d", &n, &m, &q);
for(int i = 0; i < q; i++) cin >> a[i] >> b[i];
fill(l, l+q, 0);
fill(r, r+q, m);
for(int iter = 18; iter >= 0; iter--) {
for(int i = 0; i < q; i++) if(l[i] < r[i])
ls[m - (l[i] + r[i] >> 1) + 1].push_back(i);
fill(dsu+1, dsu+n+1, -1);
for(int i: ls[m+1]) {
int mid = l[i] + r[i] >> 1;
if(root(a[i]) != root(b[i])) l[i] = mid+1;
else r[i] = mid;
}
ls[m+1].clear();
for(int x = m; x >= 1; x--) {
for(int y = 2*x; y <= n; y += x) merge(x, y);
for(int i: ls[x]) {
int mid = l[i] + r[i] >> 1;
if(root(a[i]) != root(b[i])) l[i] = mid+1;
else r[i] = mid;
}
ls[x].clear();
}
}
for(int i = 0; i < q; i++) printf("%d\n", l[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |