# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
553192 | fcmalkcin | Carnival (CEOI14_carnival) | C++17 | 10 ms | 336 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 "gap.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
//#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)
const ll maxn=3e5+100;
const ll base=3e18;
const ll mod= 1e9+7 ;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll par[maxn];
ll find_par(ll u)
{
if (u==par[u]) return u;
return par[u]=find_par(par[u]);
}
void dsu(ll x,ll y)
{
x=find_par(x);
y=find_par(y);
if (x==y) return ;
par[x]=y;
}
ll ask(vector<ll> vt)
{
cout <<vt.size()<<" ";
for (auto to:vt) cout <<to<<" ";
cout <<endl;
ll x;
cin>> x;
return x;
}
vector<ll> dosth(ll l,ll r)
{
vector<ll> vt;
if (l==r)
{
par[l]=l;
vt.pb(l);
return vt;
}
ll mid=(l+r)/2;
auto p=dosth(l,mid);
auto p1=dosth(mid+1,r);
for (auto to:p)
{
ll sl=p1.size();
vector<ll> nw=p1;
nw.pb(to);
if (ask(nw)==sl)
{
ll l=0,h=p1.size()-1;
while (l<=h)
{
ll mid=(l+h)/2;
vector<ll> nw;
nw.pb(to);
for (int i=0;i<=mid;i++) nw.pb(p1[i]);
if (ask(nw)==sl) h=mid-1;
else l=mid+1;
}
dsu(to,p1[l]);
}
}
vector<ll> res;
for (auto to:p)
{
if (to==find_par(to)) res.pb(to);
}
for (auto to:p1)
{
if (to==find_par(to)) res.pb(to);
}
return res;
}
ll col[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp","r"))
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
ll n;
cin>> n;
dosth(1,n);
ll cnt=0;
for (int i=1;i<=n;i++)
{
if (i==find_par(i)) cnt++,col[i]=cnt;
}
cout <<0<<" ";
for (int i=1;i<=n;i++) cout <<col[find_par(i)]<<" ";
cout <<endl;
}
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... |