Submission #1018683

#TimeUsernameProblemLanguageResultExecution timeMemory
1018683vjudge1Pictionary (COCI18_pictionary)C++17
140 / 140
1331 ms36500 KiB
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 1; int col[M],sz[M]; vector<int> ver[M]; void add(int x,int y) { int u=col[x],v=col[y]; if (u==v) return; if (sz[u]<sz[v]) swap(u,v); for (int i:ver[v]) { col[i]=u; ver[u].push_back(i); sz[u]++; } ver[v].clear(); sz[v]=0; } int main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int n,m,q; cin>>n>>m>>q; map<pair<int,int>,int> s,e; unordered_map<int,vector<pair<int,int>>> mid,mid1; vector<pair<int,int>> vec; while (q--) { int a,b; cin>>a>>b; s[{a,b}]=1,e[{a,b}]=m+1; mid[(m+2)/2].push_back({a,b}); vec.push_back({a,b}); } for (int qw=0;qw<18;qw++) { for (int i=1;i<=n;i++) col[i]=i,sz[i]=1,ver[i]={i}; for (int i=m;i>=1;i--) { for (int j=i+i;j<=n;j+=i) add(i,j); for (auto p:mid[i]) { if (col[p.first]==col[p.second]) s[p]=i; else e[p]=i; mid1[(s[p]+e[p])/2].push_back(p); } } mid=mid1; mid1.clear(); } for (auto i:vec) cout<<m+1-s[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...