#include<bits/stdc++.h>
#include "icc.h"
#define ll int
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
ll a[105], pa[105], Rank[105];
ll Find(ll i)
{
if (pa[i]!=i)
pa[i]=Find(pa[i]);
return pa[i];
}
void Union(ll a, ll b)
{
ll Pa=Find(a), Pb=Find(b);
if (Pa==Pb) return;
if (Rank[Pa]<Rank[Pb]) swap(Pa, Pb);
if (Rank[Pa]==Rank[Pb]) Rank[Pa]++;
pa[Pb]=Pa;
}
ll ask(vector <ll> a, vector <ll> b)
{
ll n=a.size(), m=b.size();
ll A[n], B[m];
for (ll i=0; i<a.size(); i++)
A[i]=a[i];
for (ll i=0; i<b.size(); i++)
B[i]=b[i];
return query(n, m, A, B);
}
ll random(ll l, ll r)
{
return l+rand()%(r-l+1);
}
void run(ll n)
{
srand(177013);
for (ll i=1; i<=n; i++)
pa[i]=i, a[i-1]=i;
ll lg=32-__builtin_clz(n);
for (ll j=lg-1; j>lg-2; j--)
{
for (ll i=0; i+(1<<j)<n; i++)
if (random(0, 1))
swap(a[i], a[i+(1<<j)]);
}
for (ll k=1; k<n; k++)
{
for (ll i=0; i<lg; i++)
{
vector <ll> A, B;
for (ll j=0; j<n; j++)
{
ll Pj=Find(a[j]);
if (Pj&1<<i)
A.pb(a[j]);
else B.pb(a[j]);
}
if (!ask(A, B))
continue;
ll loA=0, hiA=A.size()-1;
while (hiA>loA)
{
ll midA=(hiA+loA)/2;
vector <ll> Anew(A.begin()+loA, A.begin()+midA+1);
if (ask(Anew, B))
hiA=midA;
else loA=midA+1;
}
ll loB=0, hiB=B.size()-1;
while (hiB>loB)
{
ll midB=(hiB+loB)/2;
vector <ll> Bnew(B.begin()+loB, B.begin()+midB+1);
if (ask(A, Bnew))
hiB=midB;
else loB=midB+1;
}
setRoad(A[loA], B[loB]);
Union(A[loA], B[loB]);
break;
}
}
}
Compilation message
icc.cpp: In function 'int ask(std::vector<int>, std::vector<int>)':
icc.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (ll i=0; i<a.size(); i++)
| ~^~~~~~~~~
icc.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (ll i=0; i<b.size(); i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Ok! 106 queries used. |
2 |
Correct |
7 ms |
468 KB |
Ok! 103 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
468 KB |
Ok! 526 queries used. |
2 |
Correct |
37 ms |
476 KB |
Ok! 677 queries used. |
3 |
Correct |
36 ms |
468 KB |
Ok! 667 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
492 KB |
Ok! 1331 queries used. |
2 |
Correct |
127 ms |
496 KB |
Ok! 1672 queries used. |
3 |
Correct |
146 ms |
480 KB |
Ok! 1327 queries used. |
4 |
Correct |
108 ms |
484 KB |
Ok! 1498 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
488 KB |
Ok! 1373 queries used. |
2 |
Correct |
107 ms |
492 KB |
Ok! 1425 queries used. |
3 |
Correct |
116 ms |
468 KB |
Ok! 1587 queries used. |
4 |
Correct |
92 ms |
484 KB |
Ok! 1304 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
492 KB |
Ok! 1604 queries used. |
2 |
Correct |
118 ms |
484 KB |
Ok! 1595 queries used. |
3 |
Correct |
114 ms |
500 KB |
Ok! 1618 queries used. |
4 |
Correct |
109 ms |
488 KB |
Ok! 1545 queries used. |
5 |
Correct |
96 ms |
500 KB |
Ok! 1381 queries used. |
6 |
Correct |
108 ms |
496 KB |
Ok! 1542 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
500 KB |
Ok! 1603 queries used. |
2 |
Incorrect |
117 ms |
468 KB |
Too many queries! 1667 out of 1625 |
3 |
Halted |
0 ms |
0 KB |
- |