#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
inline ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
inline ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
const int maxN = 1e5 + 1;
//const int Mod = 1e9 + 7;
//const int inf =
int n;
struct TDSU{
vector <int> lab;
vector <pii> save;
TDSU(int _n){
lab.resize(_n, -1);
}
inline void resize(int _n){
lab.resize(_n, -1);
}
inline int find_set(int u){
return lab[u] < 0 ? u : lab[u] = find_set(lab[u]);
}
inline int find(int u){
return lab[u] < 0 ? u : find(lab[u]);
}
inline void merge(int u, int v){
if (lab[u] > lab[v]) swap(u, v);
lab[u] += lab[v];
save.pb({v, lab[v]});
lab[v] = u;
}
inline void undo(){
int v = save.back().fi;
int u = lab[v];
lab[v] = save.back().se;
lab[u] -= lab[v];
save.pop_back();
}
inline void roll_back(int _n){
while (save.size() > size_t(n)){
undo();
}
}
};
int check(int i, int j, int k = 0){
cout << j - i + 1 + bool(k) << " ";
for (int it = i; it <= j; ++it){
cout << it << " ";
}
if (k) cout << k << " ";
cout << endl;
int x; cin >> x;
return x;
}
int id[maxN], cnt;
void Init(){
cin >> n;
TDSU dsu(n + 1);
for (int i = 2; i <= n; ++i){
if (check(1, i - 1, 0) != check(1, i - 1, i)) continue;
int l = 1, r = i - 1;
while (l < r){
int mid = (l + r) >> 1;
if (check(1, mid, 0) != check(1, mid, i)) l = mid + 1;
else r = mid;
}
int x = dsu.find_set(l);
dsu.merge(x, i);
}
cout << 0 << " ";
for (int i = 1; i <= n; ++i){
int j = dsu.find_set(i);
if (!id[j]) id[j] = ++cnt;
id[i] = id[j];
cout << id[i] << " ";
}
cout << endl;
exit(0);
}
#define debug
#define taskname ""
signed main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
int tt = 1;
//cin >> tt;
while (tt--){
Init();
}
if (fopen("timeout.txt", "r")){
ofstream timeout("timeout.txt");
timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
timeout.close();
#ifndef debug
cerr << "\nTime elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
#endif // debug
}
}
Compilation message
carnival.cpp: In function 'int main()':
carnival.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
carnival.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
308 KB |
Output is correct |
2 |
Correct |
20 ms |
308 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
5 ms |
208 KB |
Output is correct |
5 |
Correct |
16 ms |
312 KB |
Output is correct |
6 |
Correct |
19 ms |
208 KB |
Output is correct |
7 |
Correct |
18 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
304 KB |
Output is correct |
2 |
Correct |
12 ms |
316 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
208 KB |
Output is correct |
5 |
Correct |
21 ms |
304 KB |
Output is correct |
6 |
Correct |
21 ms |
308 KB |
Output is correct |
7 |
Correct |
19 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
308 KB |
Output is correct |
2 |
Correct |
17 ms |
208 KB |
Output is correct |
3 |
Correct |
19 ms |
308 KB |
Output is correct |
4 |
Correct |
5 ms |
208 KB |
Output is correct |
5 |
Correct |
17 ms |
208 KB |
Output is correct |
6 |
Correct |
18 ms |
308 KB |
Output is correct |
7 |
Correct |
15 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
208 KB |
Output is correct |
2 |
Correct |
21 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
5 ms |
208 KB |
Output is correct |
5 |
Correct |
16 ms |
208 KB |
Output is correct |
6 |
Correct |
11 ms |
208 KB |
Output is correct |
7 |
Correct |
19 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
208 KB |
Output is correct |
2 |
Correct |
15 ms |
308 KB |
Output is correct |
3 |
Correct |
14 ms |
208 KB |
Output is correct |
4 |
Correct |
13 ms |
208 KB |
Output is correct |
5 |
Correct |
11 ms |
304 KB |
Output is correct |
6 |
Correct |
10 ms |
208 KB |
Output is correct |
7 |
Correct |
7 ms |
208 KB |
Output is correct |