提出 #47697553
ソースコード 拡げる
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;
#ifdef coderdhanraj
#include "libs/debug.h"
#else
#define debug(...)
#endif
#define double long double
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define vii vector<pii>
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SUM(x) accumulate(all(x), 0LL)
#define FIND(x, y) binary_search(all(x), y)
#define MEM(x, y) memset(x, y, sizeof(x))
#define CNT(x) __builtin_popcountll(x)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define bck(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define endl '\n' // remove for interactives
using i64 = int64_t; using u64 = uint64_t; using i128 = __int128_t; using u128 = __uint128_t;
/* --------------------------------------------------------- TEMPLATES --------------------------------------------------- */
class custom_hash{public: static u64 splitmix64(u64 x){ x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
size_t operator()(u64 x) const {static const u64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
template<typename P, typename Q>
size_t operator()(const pair<P, Q> &Y) const{static const u64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31ull + Y.second + FIXED_RANDOM);}
};
template<typename P, typename Q> istream& operator>>(istream &in, pair<P, Q> &p){return (in >> p.first >> p.second);}
template<typename P, typename Q> ostream& operator<<(ostream &out, const pair<P, Q> &p){return (out << p.first << " " << p.second); }
template<typename T> istream& operator>>(istream &in, vector<T> &a){for(auto &e : a) cin >> e; return in;}
template<typename T> ostream& operator<<(ostream &out, const vector<T> &a){for (auto &e : a) cout << e << " "; return out;}
template<typename T, size_t N> istream& operator>>(istream &in, array<T, N> &a){for(auto &e : a) cin >> e; return in;}
template<typename T, size_t N> ostream& operator<<(ostream &out, array<T, N> &a){for (auto &e : a) cout << e << " "; return out;}
template<typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vec = vector<vector<T>>;
template<typename P, size_t Q> using var = vector<array<P, Q>>;
template<typename P, typename Q> using indexed_map = tree<P, Q, less<P>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename P, typename Q> using gphash = gp_hash_table<P, Q, custom_hash>;
template<typename P, typename Q> using umap = unordered_map<P, Q, custom_hash>;
template<typename P, typename Q> void amax(P &x, Q y){if(x < y) x = y;}
template<typename P, typename Q> void amin(P &x, Q y){if(x > y) x = y;}
template<typename T> void unique(vector<T> &a){sort(all(a)); a.resize(unique(all(a)) - a.begin());}
template<typename T> T ceil(T x, T y){return (x >= 0 ? (x + y - 1) / y : x / y);}
template<typename T> T floor(T x, T y){return x / y - ((x ^ y) < 0 and x % y);}
template<typename T> T gcd(T x, T y){return (x ? gcd(y % x, x) : y);}
template<typename T> T lcm(T x, T y){return x / gcd(x, y) * y;}
template<typename T> T ncr(T n, T k){if (n < k){return 0;} k = min(k, n - k); T ans = 1; rep(i, 1, k + 1){ans *= (n - i + 1), ans /= i;} return ans;}
template<typename P, typename Q> P expo(P x, Q y, u64 m = LLONG_MAX){P res = 1; x = x % m; while (y > 0){if (y & 1) res = (u128)res * x % m; y = y >> 1, x = (u128)x * x % m;} return res;}
template<typename P, typename Q> P bpow(P x, Q y){P res = 1; while (y > 0){if (y & 1) res *= x; y = y >> 1, x *= x;} return res;}
template<typename P, typename Q> P inv(P n, Q m){return expo(n, m - 2, m);}
template<typename T> T sqr(T x){return x * x;}
/* --------------------------------------------------------- UNIVERSAL CONSTANTS --------------------------------------------------- */
const double eps = 1e-9;
const int mod = 1e9 + 7;// 998244353LL; // 10000000069LL; // 3006703054056749LL;
const i64 inf = 1LL << 60;
const double pi = 3.14159265358979323846264338327950;
const int dx[16] = {1, 0, 0, -1, 1, 1, -1, -1, 2, 2, 1, 1, -1, -1, -2, -2};
const int dy[16] = {0, -1, 1, 0, -1, 1, -1, 1, -1, 1, -2, 2, -2, 2, -1, 1};
/* --------------------------------------------------------- USEFUL FUNCTIONS ---------------------------------------------------- */
int testcase;
bool isOverflow(int x, int y){return (x > LLONG_MAX / y or y > LLONG_MAX / x);}
bool ispow2(int x){return (x ? !(x & (x - 1)) : 0);}
bool Case(){return cout << "Case #" << ++testcase << ": ", true;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
i64 rand(i64 x, i64 y){return uniform_int_distribution<i64>(x, y)(rng);}
#define JAI_SHREE_RAAM ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), cout.precision(20), cout.setf(ios::fixed);
/* ------------------------------------------------------- SOLUTION TO THE PROBLEM ------------------------------------------------- */
void solve(){
int n, m; cin >> n >> m;
vector<set<int>> a(n);
rep(i, 0, n){
int x; cin >> x;
a[i].insert(x);
}
rep(i, 0, m){
int x, y; cin >> x >> y, --x, --y;
if (size(a[x]) > size(a[y])) swap(a[x], a[y]);
for (auto &e : a[x]) a[y].insert(e);
a[x].clear();
cout << size(a[y]) << endl;
}
}
int32_t main(){
#ifdef coderdhanraj
auto start = high_resolution_clock::now();
freopen("error.txt", "w", stderr);
#endif
JAI_SHREE_RAAM
int ttc = 1;
// cin >> ttc;
while (ttc--) solve();
#ifdef coderdhanraj
auto time = duration_cast<microseconds>(high_resolution_clock::now() - start).count() / 1000;
cerr << "Time: " << time << " ms!" << endl;
#endif
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
F - Colored Ball |
| ユーザ |
coderdhanraj |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
500 |
| コード長 |
6360 Byte |
| 結果 |
AC |
| 実行時間 |
284 ms |
| メモリ |
25084 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample00.txt, sample01.txt |
| All |
sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| sample00.txt |
AC |
1 ms |
3520 KiB |
| sample01.txt |
AC |
1 ms |
3552 KiB |
| testcase00.txt |
AC |
51 ms |
21812 KiB |
| testcase01.txt |
AC |
57 ms |
21800 KiB |
| testcase02.txt |
AC |
119 ms |
21840 KiB |
| testcase03.txt |
AC |
139 ms |
21800 KiB |
| testcase04.txt |
AC |
114 ms |
21836 KiB |
| testcase05.txt |
AC |
145 ms |
21780 KiB |
| testcase06.txt |
AC |
131 ms |
21844 KiB |
| testcase07.txt |
AC |
128 ms |
21804 KiB |
| testcase08.txt |
AC |
127 ms |
21844 KiB |
| testcase09.txt |
AC |
121 ms |
21844 KiB |
| testcase10.txt |
AC |
129 ms |
21884 KiB |
| testcase11.txt |
AC |
146 ms |
21852 KiB |
| testcase12.txt |
AC |
63 ms |
20788 KiB |
| testcase13.txt |
AC |
69 ms |
21836 KiB |
| testcase14.txt |
AC |
63 ms |
20476 KiB |
| testcase15.txt |
AC |
71 ms |
21772 KiB |
| testcase16.txt |
AC |
80 ms |
21272 KiB |
| testcase17.txt |
AC |
83 ms |
21848 KiB |
| testcase18.txt |
AC |
73 ms |
20744 KiB |
| testcase19.txt |
AC |
79 ms |
21804 KiB |
| testcase20.txt |
AC |
80 ms |
21788 KiB |
| testcase21.txt |
AC |
72 ms |
21828 KiB |
| testcase22.txt |
AC |
86 ms |
21852 KiB |
| testcase23.txt |
AC |
77 ms |
21780 KiB |
| testcase24.txt |
AC |
70 ms |
21560 KiB |
| testcase25.txt |
AC |
86 ms |
21844 KiB |
| testcase26.txt |
AC |
65 ms |
21040 KiB |
| testcase27.txt |
AC |
72 ms |
21824 KiB |
| testcase28.txt |
AC |
77 ms |
20352 KiB |
| testcase29.txt |
AC |
80 ms |
21780 KiB |
| testcase30.txt |
AC |
67 ms |
20212 KiB |
| testcase31.txt |
AC |
74 ms |
21828 KiB |
| testcase32.txt |
AC |
88 ms |
21516 KiB |
| testcase33.txt |
AC |
74 ms |
21784 KiB |
| testcase34.txt |
AC |
73 ms |
20444 KiB |
| testcase35.txt |
AC |
85 ms |
21796 KiB |
| testcase36.txt |
AC |
71 ms |
21304 KiB |
| testcase37.txt |
AC |
73 ms |
21808 KiB |
| testcase38.txt |
AC |
76 ms |
20212 KiB |
| testcase39.txt |
AC |
89 ms |
21788 KiB |
| testcase40.txt |
AC |
284 ms |
22428 KiB |
| testcase41.txt |
AC |
284 ms |
25084 KiB |