# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534656 | shrimb | Carnival (CEOI14_carnival) | C++17 | 10 ms | 328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include"bits/stdc++.h"
#define int long long
// #define endl '\n'
using namespace std;
int dsu[2000001];
int ans[2000001];
int Find (int x) {
return dsu[x] == x ? x : dsu[x] = Find(dsu[x]);
}
void Union (int a, int b) {
dsu[Find(a)] = Find(b);
}
int Query (vector<int> v, int x) {
cout << v.size() + 1 << " ";
for (int i : v) cout << i << " ";
cout << x;
cout << endl;
int X;
cin >> X;
return X;
}
signed main () {
int n;
cin >> n;
vector<int> num;
for (int i = 1 ; i <= n ; i++) dsu[i] = i;
num = {1};
for (int i = 2 ; i <= n ; i++) {
// cerr << "Query: " << Query(num, i) << endl;
if (Query(num, i) == num.size() + 1) num.push_back(i);
else {
int l = 0, r = num.size() - 1;
while (r > l) {
int m = (l + r) / 2;
if (Query(vector<int>(num.begin() + l, num.begin() + m + 1), i) == m - l + 1) {
r = m;
} else l = m + 1;
}
Union(num[l], i);
}
}
// cerr << "dbg: ";
// for (int i : num) cout << i << " ";
// cout << endl;
int c = 1;
for (int i = 1 ; i <= n ; i++) if (dsu[i] == i) ans[i] = c++;
cout << 0 << " ";
for (int i = 1 ; i <= n ; i++) cout << ans[Find(i)] << " ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |