Submission #93517

#TimeUsernameProblemLanguageResultExecution timeMemory
93517dfistricPictionary (COCI18_pictionary)C++14
140 / 140
413 ms15860 KiB
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORd(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) FOR(i, 0, n) typedef long long ll; using namespace std; const int MAXN = 1e5 + 10; int lo[MAXN], hi[MAXN]; vector <int> mi[MAXN]; int a[MAXN], b[MAXN]; int par[MAXN]; int nadi(int x) { if (x != par[x]) par[x] = nadi(par[x]); return par[x]; } void spoji(int x, int y) { x = nadi(x); y = nadi(y); par[y] = x; return; } int main() { ios_base::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; REP(i, q) { cin >> a[i] >> b[i]; lo[i] = 1; hi[i] = m; } REP(bi, 20) { REP(i, n + 1) par[i] = i; REP(i, q) { int mid = (lo[i] + hi[i]) / 2; mi[mid].push_back(i); } FORd(k, m, 1) { int st = k + k; while (st <= n) { spoji(k, st); st += k; } int p = m - k + 1; for (int ne : mi[p]) { if (nadi(a[ne]) == nadi(b[ne])) { hi[ne] = p; } else { lo[ne] = p + 1; } } mi[p].clear(); } } REP(i, q) cout << lo[i] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...