結果

問題 No.1059 素敵な集合
ユーザー TAISA_TAISA_
提出日時 2020-05-22 21:54:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 2,303 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 196,676 KB
最終ジャッジ日時 2025-01-10 14:41:02
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
void dump() {
cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//@docs Docs/UnionFind.md
struct UnionFind {
vector<int> par, sz;
int cnt;
UnionFind(int n) : par(n), sz(n, 1) {
iota(par.begin(), par.end(), 0);
cnt = n;
}
inline int find(int x) {
if (x == par[x]) return x;
return par[x] = find(par[x]);
}
bool unite(int u, int v) {
u = find(u), v = find(v);
if (u == v) return false;
--cnt;
if (sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
return true;
}
inline int size(int x) {
return sz[find(x)];
}
inline bool same(int u, int v) {
return find(u) == find(v);
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int l, r;
cin >> l >> r;
int res = 0;
UnionFind uf(r - l + 1);
for (int i = l; i <= r; i++) {
for (int j = i + i; j <= r; j += i) {
uf.unite(i - l, j - l);
}
}
cout << uf.cnt - 1 << newl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0