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>
#pragma GCC optimization ("O3")
using namespace std;
const int N = 157;
static int lab[N], ans[N], n, cnt;
set<int> s;
int Find(int u)
{
return lab[u] < 0? u: lab[u] = Find(lab[u]);
}
void Union(int u, int v)
{
int s = Find(u), r = Find(v);
if(s == r) return;
if(lab[r] > lab[s]) swap(r, s);
lab[r] += lab[s];
lab[s] = r;
}
int ask(int x, int l, int r)
{
int len = (x != -1) + r - l + 1;
cout << len << ' ';
for(int i = l; i <= r; ++i) cout << i + 1 << ' ';
if(x != -1) cout << x + 1 << ' ';
cout << '\n';
cin >> len;
return len;
}
int GetAns(int l, int r)
{
s.clear();
for(int i = l; i <= r; ++i) s.insert(Find(i));
return int(s.size());
}
void UNION(int x, int lef, int rig)
{
if(ask(x, lef, rig) != GetAns(lef, rig)) return;
int l = lef, h = rig, mid, cc;
while(l < h) {
mid = (l + h) >> 1;
cc = ask(x, l, mid);
if(cc == GetAns(l, mid)) h = mid;
else l = mid + 1;
}
Union(x, l);
}
void Divide(int l, int r)
{
if(l >= r) return;
if(r - l == 1) {
int cc = ask(-1, l, r);
if(cc == 1) Union(l, r);
return;
}
int mid = (l + r) >> 1;
Divide(l, mid); Divide(mid + 1, r);
set<int> irene;
for(int i = l; i <= mid; ++i) {
int x = Find(i);
if(irene.find(x) == irene.end()) UNION(i, mid + 1, r), irene.insert(x);
}
}
int main()
{
cin >> n;
memset(&lab, -1, sizeof lab);
Divide(0, n - 1);
for(int i = 0; i < n; ++i) s.insert(Find(i));
for(int x: s) ans[x] = ++cnt;
cout << "0 ";
for(int i = 0; i < n; ++i) cout << ans[Find(i)] << ' ';
}
Compilation message (stderr)
carnival.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
# | 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... |