Submission #746222

#TimeUsernameProblemLanguageResultExecution timeMemory
746222JuanPictionary (COCI18_pictionary)C++17
140 / 140
213 ms3656 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, INF = 0x3f3f3f3f; struct node{ int id, pai, edge, sz; }; struct DSU{ node v[maxn]; void init(int n){ for(int i = 1; i <= n; i++) v[i] = {i, i, INF, 1}; } int find(int x){return (v[x].pai==x ? x : find(v[x].pai));} void join(int a, int b, int k){ a = find(a), b = find(b); if(a==b) return; if(v[a].sz > v[b].sz) swap(a, b); v[a] = {a, b, k, v[a].sz}; v[b].sz += v[a].sz; } void query(int a, int b){ int ans = 0; while(a!=b){ if(v[a].edge < v[b].edge) ans = max(ans, v[a].edge), a = v[a].pai; else ans = max(ans, v[b].edge), b = v[b].pai; } cout << ans << '\n'; } }dsu; int main(){ int n, m, q; cin >> n >> m >> q; dsu.init(n); for(int i = m; i >= 1; i--){ for(int j = i+i; j <= n; j+=i) dsu.join(i, j, m-i+1); } while(q--){ int a, b; cin >> a >> b; dsu.query(a, b); } }
#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...