# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
347927 | Uncreative | Pictionary (COCI18_pictionary) | C++14 | 596 ms | 15224 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<iostream>
#include<vector>
#include<ctime>
#include<random>
#include<cmath>
using namespace std;
const int maxn = 100010;
int par[maxn];
int Find(int x){
if (x != par[x]){
par[x] = Find(par[x]);
}
return par[x];
}
void Union(int x, int y){
x = Find(x);
y = Find(y);
if (x == y){
return;
}
int c = (rand()%2);
if (c == 0){
par[x] = y;
}
else {
par[y] = x;
}
}
int a[maxn];
int b[maxn];
int sol[maxn];
int lo[maxn];
int hi[maxn];
vector<int> md[maxn];
int main(){
srand(time(0));
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= q; i++){
cin >> a[i] >> b[i];
}
for (int i = 1; i <= q; i++){
lo[i] = 1;
hi[i] = m;
md[(lo[i] + hi[i]) / 2].push_back(i);
}
int lg = (int)log2((double)m) + 3;
for (int t = 0; t < lg; t++){
for (int i = 1; i <= n; i++){
par[i] = i;
}
for (int i = 1; i <= m; i++){
int mi = m - i + 1;
for (int j = mi; j <= n - mi; j += mi){
Union(j, j + mi);
}
for (int j = 0; j < md[i].size(); j++){
int e = md[i][j];
if (Find(a[e]) == Find(b[e])){
sol[e] = i;
hi[e] = i;
}
else {
lo[e] = i + 1;
}
}
md[i].clear();
}
for (int i = 1; i <= q; i++){
md[(lo[i] + hi[i]) / 2].push_back(i);
}
}
for (int i = 1; i <= q; i++){
cout << sol[i] << "\n";
}
}
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... |