#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod =1e9 + 7;
const int mxn = 250000 + 5, mxq = 1e5 + 5, sq = 300, mxv = 1e4 + 5;
//const int base = (1 <<18);
const ll inf = 3e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
// <3;
int bit[mxn + 1], c[mxn + 1], to[mxn + 1];
int n;
void upd(int p, int v){
while(p <= n){
bit[p] += v; p += p & (-p);
}
}
int get(int p){
int ans = 0;
while(p){
ans += bit[p]; p -= p & (-p);
}
return(ans);
}
int query(int l, int r){
return(get(r) - get(l - 1));
}
int ask(int l, int r){
cout << r - l + 1 << " ";
for(int i = l; i <= r; i++)cout << i << " ";
cout << endl;
int x; cin >> x;
return(x);
}
void solve(){
cin >> n;
for(int i = n; i >= 1; i--){
upd(i, 1);
if(query(i, n) == ask(i, n)){
to[i] = n + 1; continue;
}
int l = i + 1, r = n, ans;
while(l <= r){
int mid = (l + r) >> 1;
if(ask(i, mid) != query(i, mid)){
ans = mid; r = mid - 1;
}else{
l = mid + 1;
}
}
to[i] = ans; upd(ans, -1);
}
int idc = 0;
for(int i = n; i >= 1; i--){
if(to[i] == n + 1)c[i] = ++idc;
else c[i] = c[to[i]];
}
cout << 0 << " ";
for(int i = 1; i <= n; i++)cout << c[i] << " ";
cout << endl;
return;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("SODOCLA.INP", "r", stdin);
//freopen("SODOCLA.INP", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
/*
10 5
2 3 4 5 6
*/
Compilation message
carnival.cpp: In function 'void solve()':
carnival.cpp:71:15: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
71 | to[i] = ans; upd(ans, -1);
| ~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2392 KB |
Output is correct |
2 |
Correct |
4 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2388 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
4 ms |
2392 KB |
Output is correct |
6 |
Correct |
4 ms |
2392 KB |
Output is correct |
7 |
Correct |
4 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
5 ms |
2392 KB |
Output is correct |
6 |
Correct |
4 ms |
2392 KB |
Output is correct |
7 |
Correct |
5 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2392 KB |
Output is correct |
2 |
Correct |
6 ms |
2392 KB |
Output is correct |
3 |
Correct |
4 ms |
2392 KB |
Output is correct |
4 |
Correct |
3 ms |
2392 KB |
Output is correct |
5 |
Correct |
4 ms |
2392 KB |
Output is correct |
6 |
Correct |
4 ms |
2392 KB |
Output is correct |
7 |
Correct |
5 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
4 ms |
2392 KB |
Output is correct |
6 |
Correct |
3 ms |
2392 KB |
Output is correct |
7 |
Correct |
4 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2392 KB |
Output is correct |
3 |
Correct |
4 ms |
2392 KB |
Output is correct |
4 |
Correct |
4 ms |
2392 KB |
Output is correct |
5 |
Correct |
3 ms |
2392 KB |
Output is correct |
6 |
Correct |
3 ms |
2392 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |