Submission #886899

#TimeUsernameProblemLanguageResultExecution timeMemory
886899vjudge1Pictionary (COCI18_pictionary)C++17
140 / 140
164 ms4096 KiB
#include <bits/stdc++.h> using namespace std; #define sp << " " << #define int long long #define vi vector<int> #define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++) #define pii pair<int,int> #define pb push_back const int N = 1e5+1; vi dad(N),change(N),sz(N,1); int find(int x,int t) { if (x == dad[x] || change[x] > t) return x; return find(dad[x],t); } void unite(int x,int y,int t) { int a = find(x,t),b = find(y,t); if (a == b) return; if (sz[a] > sz[b]) swap(a,b); sz[b]+=sz[a]; dad[a] = b; change[a] = t; } void solve() { int n,m,q; cin >> n >> m >> q; F(i,n) dad[i] = i; for (int i=m;i>=1;i--) { for (int j=i;j+i<=n;j+=i) unite(j,j+i,m-i+1); } while (q--) { int a,b; cin >> a >> b; int l = 1; int r = m; while (l<=r) { int mm = (l+r) >>1; if (find(a,mm) == find(b,mm)) r = mm-1; else l = mm+1; } cout << l << endl; } } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif int t = 1; //cin >> t; F(i,t) solve(); }
#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...