結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-05-22 21:53:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 1,798 bytes |
コンパイル時間 | 3,761 ms |
コンパイル使用メモリ | 239,136 KB |
最終ジャッジ日時 | 2025-01-10 14:40:48 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<long long, long long>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; } template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// struct UnionFind { vector<int> node; UnionFind() = default; UnionFind(int x) {init(x);} void init(int x) { node.assign(x,-1); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (node[x] > node[y]) swap(x,y); node[x] += node[y]; node[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int root(int x) { if (node[x] < 0) return x; return node[x] = root(node[x]); } int size(int x) { return -node[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int L,R; cin >> L >> R; UnionFind uf(R-L+1); for (int i = L; i <= R; i++) { for (int j = 2; j*i <= R; j++) { uf.merge(i-L,j*i-L); } } set<int> dic; rep(i,R-L+1) { dic.emplace(uf.root(i)); } cout << dic.size()-1 << ln; }