結果

問題 No.1059 素敵な集合
ユーザー uenokuuenoku
提出日時 2020-05-23 19:55:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 2,591 ms
コンパイル使用メモリ 187,228 KB
実行使用メモリ 8,860 KB
最終ジャッジ日時 2023-09-30 15:37:43
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 19 ms
5,408 KB
testcase_02 AC 12 ms
4,764 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 11 ms
4,584 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 15 ms
5,096 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 24 ms
5,900 KB
testcase_16 AC 10 ms
4,632 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 28 ms
8,860 KB
testcase_19 AC 21 ms
5,800 KB
testcase_20 AC 22 ms
6,080 KB
testcase_21 AC 26 ms
6,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
struct ufind {
  struct node {
    int par, rank, size;
    void init(int i) {
      par = i;
      rank = 0;
      size = 1;
    }
  };
  vector<node> nodes;
  ufind(int n) {
    nodes.resize(n);
    rep(i, n) nodes[i].init(i);
  }
  int find(int x) {
    return nodes[x].par == x ? x : (nodes[x].par = find(nodes[x].par));
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (nodes[x].rank < nodes[y].rank) {
      nodes[x].par = y;
      nodes[y].size += nodes[x].size;
    } else {
      nodes[y].par = x;
      if (nodes[x].rank == nodes[y].rank)
        nodes[x].rank++;
      nodes[x].size += nodes[y].size;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return nodes[find(x)].size; }
};
int main()
{
  int l, r;
  cin >> l >> r;
  ufind uf(r-l+1);
  
  for(int i = l;i<=r;i++){
    for(int j = i;j<=r;j+=i){
      uf.unite(i-l, j-l);
    }
  }
  set<int> s;
  rep(i, r-l+1){
    s.insert(uf.find(i));
  }
  cout << s.size()-1 <<endl;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
    return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
    return (l < r) ? (l = r, true) : false;
}
0