Submission #649851

#TimeUsernameProblemLanguageResultExecution timeMemory
649851inksamuraiPictionary (COCI18_pictionary)C++17
140 / 140
195 ms23184 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rng(i,c,n) for(int i=c;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3yqVz8E ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vector<int>; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} // e int pvt; const int _n=100011; int pns[_n]; struct dsu{ int _n; vi si,par; vec(set<int>) qry; dsu(int n=0){ init(n); } void init(int n=0){ _n=n; par=vi(_n,0); si=vi(_n,0); qry.clear(); qry=vec(set<int>)(_n); rep(i,n){ si[i]=1; par[i]=i; } } int parent(int u){return par[u]=(par[u]==u?u:parent(par[u]));} bool same(int u,int v){return parent(u)==parent(v);} void merge(int u,int v){ u=parent(u),v=parent(v); if(!same(u,v)){ if(si[u]<si[v])swap(u,v); vi delay; for(auto id:qry[v]){ if(qry[u].find(id)!=qry[u].end()){ qry[u].erase(qry[u].find(id)); pns[id]=pvt; }else{ delay.pb(id); } } for(auto id:delay)qry[u].insert(id); _n-=1; si[u]+=si[v]; par[v]=u; } } int size(int v=-1){return v==-1?_n:si[parent(v)];} }; signed main(){ _3yqVz8E; int n,m,q; cin>>n>>m>>q; dsu uf(n); rep(i,q){ int u,v; cin>>u>>v; u-=1,v-=1; uf.qry[v].insert(i); uf.qry[u].insert(i); } for(int i=m;i>=1;i--){ pvt=m-i+1; for(int j=i;j<=n;j+=i){ uf.merge(i-1,j-1); } } rep(i,q){ cout<<(pns[i])<<"\n"; } }
#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...