Submission #347721

#TimeUsernameProblemLanguageResultExecution timeMemory
347721Harry464Pictionary (COCI18_pictionary)C++14
0 / 140
1600 ms6728 KiB
#include <iostream> #include <vector> #include <set> #include <cmath> #include <algorithm> #include <queue> #include <map> using namespace std; typedef long long ll; int main() { ll n, m, q; cin >> n >> m >> q; vector <pair <ll, ll>> kv(q); for (int i = 0; i < q; i++) cin >> kv[i].first >> kv[i].second; vector <ll> lo(q, 1); vector <ll> hi(q, m + 1); vector <ll> rjesenja(q, -1); ll rjeseni = 0; while (rjeseni < q){ vector <pair <ll,ll>> mids(q); for (int i = 0; i < q; i++) mids[i].first = (lo[i]+hi[i])/2, mids[i].second = i; sort(mids.begin(), mids.end()); vector <ll> par(n); for (int i = 0; i < n; i++) par[i] = i; ll slid = 0; for (int i = 0; i < m; i++){ ll tren = 2*(m - i); while (tren <= n){ ll part = tren-1; while (part != par[part]) part = par[part]; par[part] = m - i - 1; tren += m - i; } while (slid <= n && mids[slid].first == i + 1){ ll upit = mids[slid].second; if (rjesenja[upit] != -1){ slid++; continue; } ll para = kv[upit].first-1, parb = kv[upit].second-1; while (para != par[para]) para = par[para]; while (parb != par[parb]) parb = par[parb]; if (para == parb){ hi[upit] = i + 1; } else { lo[upit] = i + 2; } if (lo[upit] >= hi[upit]){ rjeseni++, rjesenja[upit] = lo[upit]; } slid++; } } } for (int i = 0; i < q; i++) cout << rjesenja[i] << endl; }
#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...