# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
94696 | johnjq | Pictionary (COCI18_pictionary) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> ii;
using std::swap;
const int MAX_N = 100000;
#include "../codes/uf-partial-1.cpp"
#include "../codes/uf-partial-2.cpp"
bool same(int u, int v, int t) {
return find(u, t) == find(v, t);
}
inline int find_time(int a, int b) {
int ans = -1;
int l = 0, r = tempo;
while (l <= r) {
const int m = (l+r)/2;
if (same(a, b, m)) {
ans = m;
r = m-1;
} else {
l = m+1;
}
}
return ans;
}
int32_t main() {
using namespace std;
ios::sync_with_stdio(false);
cin.tie(0);
init();
int n, m, q;
cin>>n>>m>>q;
map<int, int> ans;
ans[tempo] = 0;
for (int day = m; day >= 1; --day) {
for (int i = 2; i*day <= n; ++i) {
if (!same(day, i*day, tempo))
merge(day, i*day);
else
tempo += 1;
ans[tempo] = m-day+1;
}
}
while (q--) {
int a, b;
cin>>a>>b;
int time = find_time(a, b);
cout<<ans[time]<<'\n';
}
}