結果

問題 No.1059 素敵な集合
ユーザー auauaauaua
提出日時 2020-05-22 22:11:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,314 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 168,160 KB
実行使用メモリ 9,448 KB
最終ジャッジ日時 2023-09-30 15:29:22
合計ジャッジ時間 2,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,672 KB
testcase_01 AC 20 ms
9,448 KB
testcase_02 AC 5 ms
6,912 KB
testcase_03 AC 2 ms
5,604 KB
testcase_04 AC 2 ms
5,456 KB
testcase_05 AC 2 ms
5,388 KB
testcase_06 AC 4 ms
6,328 KB
testcase_07 AC 4 ms
6,408 KB
testcase_08 AC 5 ms
6,732 KB
testcase_09 AC 3 ms
5,748 KB
testcase_10 AC 6 ms
7,220 KB
testcase_11 AC 5 ms
6,704 KB
testcase_12 AC 3 ms
5,960 KB
testcase_13 AC 7 ms
7,208 KB
testcase_14 AC 2 ms
5,636 KB
testcase_15 AC 11 ms
8,836 KB
testcase_16 AC 5 ms
6,684 KB
testcase_17 AC 5 ms
6,644 KB
testcase_18 AC 6 ms
9,436 KB
testcase_19 AC 19 ms
9,360 KB
testcase_20 AC 19 ms
9,376 KB
testcase_21 AC 11 ms
9,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0