#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
#define MP make_pair
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 222;
int p[N];
int find(int x){
return (x == p[x] ? x : p[x] = find(p[x]));
}
void unite(int x, int y){
x = find(x);
y = find(y);
if (x == y) return;
if (rng() & 1) swap(x, y);
p[x] = y;
}
vector<int> mv(int l, int r){
vector<int> res;
while (l <= r) res.push_back(l++);
return res;
}
int sz(vector<int> v){
set<int> s;
for (int i : v) s.insert(find(i));
return s.size();
}
bool local = false;
int secret[N];
int MaxQ = 0;
int queries = 0;
int ask(vector<int> v){
queries++;
MaxQ = max(MaxQ, queries);
if (local){
set<int> s;
for (int i : v) s.insert(secret[i]);
return s.size();
}
cout << v.size() << ' ';
for (int i : v) cout << i << ' ';
cout << endl;
int res;
cin >> res;
return res;
}
int rand(int l, int r){
return l + rng() % (r - l + 1);
}
int answer[N];
void solve(int TC) {
int n;
// cin >> n;
queries = 0;
// local = true;
if (local){
n = rand(1, 150);
for (int i = 1; i <= n; i++){
// cin >> secret[i];
secret[i] = rand(1, n);
}
} else {
cin >> n;
}
iota(p + 1, p + n + 1, 1);
vector<bool> used(n + 1, false);
for (int i = 1; i < n; i++){
while (true) {
int l = i + 1, r = n;
int ind = i;
while (l <= r) {
int m = (l + r) >> 1;
if (ask(mv(i, m)) == sz(mv(i, m))) {
ind = m;
l = m + 1;
} else r = m - 1;
}
if (ind == n) break;
if (used[ind]) continue;
used[ind] = true;
l = i, r = ind;
ind++;
int ind2 = i;
while (l <= r) {
int m = (l + r) >> 1;
if (ask(mv(m, ind)) < sz(mv(m, ind))) {
ind2 = m;
l = m + 1;
} else r = m - 1;
}
unite(ind2, ind);
// debug(ind2, ind);
}
}
map<int, int> mp;
for (int i = 1; i <= n; i++){
int x = find(i);
if (mp.find(x) == mp.end()) mp[x] = mp.size() + 1;
}
for (int i = 1; i <= n; i++) answer[i] = mp[find(i)];
if (mp.size() != ask(mv(1, n))){
for (int i = 1; i <= n; i++) cout << secret[i] << ' '; cout << endl;
for (int i = 1; i <= n; i++) cout << answer[i] << ' '; cout << endl;
assert(false);
}
if (!local) {
cout << 0 << ' ';
for (int i = 1; i <= n; i++) {
cout << answer[i] << ' ';
}
cout << endl;
}
// debug(queries);
if (local){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
bool b1 = answer[i] == answer[j];
bool b2 = secret[i] == secret[j];
assert(b1 == b2);
}
}
}
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef dddxxz
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int TC = 1;
// cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
debug(MaxQ);
cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
Compilation message
carnival.cpp: In function 'void solve(int)':
carnival.cpp:157:19: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
157 | if (mp.size() != ask(mv(1, n))){
| ~~~~~~~~~~^~~~~~~~~~~~~~~~
carnival.cpp:158:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
158 | for (int i = 1; i <= n; i++) cout << secret[i] << ' '; cout << endl;
| ^~~
carnival.cpp:158:64: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
158 | for (int i = 1; i <= n; i++) cout << secret[i] << ' '; cout << endl;
| ^~~~
carnival.cpp:159:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
159 | for (int i = 1; i <= n; i++) cout << answer[i] << ' '; cout << endl;
| ^~~
carnival.cpp:159:64: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
159 | for (int i = 1; i <= n; i++) cout << answer[i] << ' '; cout << endl;
| ^~~~
carnival.cpp: In function 'int main()':
carnival.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
carnival.cpp:203:5: note: in expansion of macro 'debug'
203 | debug(MaxQ);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
328 KB |
Output is correct |
2 |
Correct |
35 ms |
328 KB |
Output is correct |
3 |
Correct |
22 ms |
340 KB |
Output is correct |
4 |
Correct |
18 ms |
328 KB |
Output is correct |
5 |
Correct |
27 ms |
328 KB |
Output is correct |
6 |
Correct |
36 ms |
328 KB |
Output is correct |
7 |
Correct |
35 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
328 KB |
Output is correct |
2 |
Correct |
45 ms |
328 KB |
Output is correct |
3 |
Correct |
20 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
328 KB |
Output is correct |
5 |
Correct |
36 ms |
328 KB |
Output is correct |
6 |
Correct |
38 ms |
344 KB |
Output is correct |
7 |
Correct |
33 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
332 KB |
Output is correct |
2 |
Correct |
28 ms |
328 KB |
Output is correct |
3 |
Correct |
43 ms |
328 KB |
Output is correct |
4 |
Correct |
22 ms |
448 KB |
Output is correct |
5 |
Correct |
38 ms |
328 KB |
Output is correct |
6 |
Correct |
32 ms |
328 KB |
Output is correct |
7 |
Correct |
37 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
328 KB |
Output is correct |
2 |
Correct |
40 ms |
328 KB |
Output is correct |
3 |
Correct |
27 ms |
328 KB |
Output is correct |
4 |
Correct |
18 ms |
328 KB |
Output is correct |
5 |
Correct |
38 ms |
328 KB |
Output is correct |
6 |
Correct |
32 ms |
328 KB |
Output is correct |
7 |
Correct |
40 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
328 KB |
Output is correct |
2 |
Correct |
41 ms |
448 KB |
Output is correct |
3 |
Correct |
26 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
340 KB |
Output is correct |
5 |
Correct |
27 ms |
328 KB |
Output is correct |
6 |
Correct |
26 ms |
344 KB |
Output is correct |
7 |
Correct |
23 ms |
328 KB |
Output is correct |