Submission #237565

#TimeUsernameProblemLanguageResultExecution timeMemory
237565NONAMEPictionary (COCI18_pictionary)C++17
140 / 140
341 ms15092 KiB
#include <bits/stdc++.h> #define sz(x) int(x.size()) #define pb push_back #define mp make_pair #define ft first #define sd second #define el '\n' using namespace std; typedef long long ll; const int N = 1e5 + 10; int n, m, q; int l[N], r[N], a[N], b[N], pr[N]; vector <int> v[N]; int f(int x) { return (x == pr[x]) ? x : pr[x] = f(pr[x]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; for (int i = 0; i < q; ++i) { cin >> a[i] >> b[i]; l[i] = 1, r[i] = m; } bool mk = 1; while (mk) { for (int i = 1; i <= n; ++i) pr[i] = i; mk = 0; for (int i = 0; i < q; ++i) { if (l[i] == r[i]) continue; int md = (l[i] + r[i]) >> 1; v[md].pb(i); mk = 1; } for (int md = 1; md <= m; ++md) { int p = m - md + 1; for (int j = p; j <= n; j += p) pr[f(j)] = f(p); for (int j = 0; j < sz(v[md]); ++j) { int x = v[md][j]; if (f(a[x]) == f(b[x])) r[x] = md; else l[x] = md + 1; } v[md].clear(); } } for (int i = 0; i < q; ++i) cout << l[i] << el; }
#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...