結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-05-22 22:11:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 1,314 bytes |
コンパイル時間 | 1,562 ms |
コンパイル使用メモリ | 170,012 KB |
実行使用メモリ | 9,520 KB |
最終ジャッジ日時 | 2024-07-23 09:29:50 |
合計ジャッジ時間 | 2,449 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll inf=1e9+7; const ll mod=1e9+7; //高速化Union-Find木 int siz[200010]; int par[200010]; int depth[200010]; void init(int n){ for(int i=0;i<=n;i++){ par[i]=i; depth[i]=0; } rep(i,n+1){ siz[i]=1; } } int root(int x){ return par[x]==x?x:par[x]=root(par[x]); } bool same(int x,int y){ return root(x)==root(y); } void unite(int x,int y){ x=root(x); y=root(y); ll sx=siz[x]; ll sy=siz[y]; if(x==y)return; if(depth[x]<depth[y]){ par[x]=y; }else{ par[y]=x; if(depth[x]==depth[y])depth[x]++; } siz[root(x)]=sx+sy; } signed main(){ ll l,r;cin>>l>>r; ll ans=0; init(r); REP(i,l,r+1){ ll d=2; while(d*i<=r){ unite(i,d*i); d++; } } vector<ll>used(r+1); REP(i,l,r+1){ if(used[root(i)])continue; ans++; used[root(i)]=1; } ans--; cout<<ans<<endl; }