結果
問題 |
No.1059 素敵な集合
|
ユーザー |
|
提出日時 | 2021-01-16 17:14:39 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 1,682 bytes |
コンパイル時間 | 3,786 ms |
コンパイル使用メモリ | 144,776 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-11-27 21:18:34 |
合計ジャッジ時間 | 5,916 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
// // Created by zeronosu77108 on Jan 15, 2021. // #include <iostream> #include <iomanip> #include <vector> #include <utility> #include <map> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <queue> #include <cmath> #include <numeric> #include <set> #include <complex> #include <optional> #include <climits> using namespace std; struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa; template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;} #define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<(v)<<endl;} class UnionFind { private: vector<optional<int>> _par; vector<int>_size; public: explicit UnionFind(const int n) : _par(n+1), _size(n+1, 1) {} int root(const int x) { if (!_par[x]) return x; _par[x] = root(_par[x].value()); return _par[x].value(); } bool is_same(const int x, const int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x==y) return false; if (_size[x] < _size[y]) swap(x,y); _par[y] = x; _size[x] += _size[y]; return true; } int size(const int x) { return _size[x]; } }; int main() { int l, r; cin >> l >>r; unordered_map<long, long> mp; UnionFind uni(2*100'000); for (int i=l; i<=r; i++) { for (int j=2*i; j<=r; j+=i) uni.merge(i, j); } long ans = 0; for (int i=l; i<=r; i++) { if (i == uni.root(i)) ans++; } cout << ans - 1 << endl; }