#include <bits/stdc++.h>
#include "icc.h"
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 1000010
#define pa pair<ll, ll>
#define ld long double
vc<vc<ll>> dsu;
int aA[105], aB[105];
ll quer(int sa, int sb, vc<ll> a, vc<ll> b){
loop(i, 0, sa) aA[i]=a[i];
loop(i, 0, sb) aB[i]=b[i];
return query(sa, sb, aA, aB);
}
ll dsuque(vc<ll> a, vc<ll> b){
vc<ll> qa, qb;
fore(v, a) fore(u, dsu[v]) qa.ps(u);
fore(v, b) fore(u, dsu[v]) qb.ps(u);
return quer(qa.size(), qb.size(), qa, qb);
}
pa solve(){
vc<ll> fa, fb;
if(dsu.size()==2){
fa.ps(0);
fb.ps(1);
}
else{
vc<pa> arr[2];
arr[0].ps(make_pair(0, dsu.size()));
while(1){
vc<pa> temp[2];
fore(v, arr[0]){
if(v.fi==v.se-1){
temp[0].ps(v);
continue;
}
ll mid=v.fi+v.se;mid/=2;
temp[0].ps(make_pair(v.fi, mid));
temp[1].ps(make_pair(mid, v.se));
}
fore(v, arr[1]){
if(v.fi==v.se-1){
temp[1].ps(v);
continue;
}
ll mid=v.fi+v.se;mid/=2;
temp[0].ps(make_pair(v.fi, mid));
temp[1].ps(make_pair(mid, v.se));
}
arr[0]=temp[0];
arr[1]=temp[1];
vc<ll> a, b;
fore(v, arr[0]) loop(i, v.fi, v.se) a.ps(i);
fore(v, arr[1]) loop(i, v.fi, v.se) b.ps(i);
if(dsuque(a, b)){
fa=a, fb=b;
break;
}
}
}
while(fa.size()>1){
vc<ll> l[2];
loop(i, 0, fa.size()) l[i%2].ps(fa[i]);
if(dsuque(l[0], fb)) fa=l[0];
else fa=l[1];
}
while(fb.size()>1){
vc<ll> l[2];
loop(i, 0, fb.size()) l[i%2].ps(fb[i]);
if(dsuque(l[0], fa)) fb=l[0];
else fb=l[1];
}
vc<ll> ta=dsu[fa[0]], tb=dsu[fb[0]];
while(ta.size()>1){
vc<ll> l[2];
loop(i, 0, ta.size()) l[i%2].ps(ta[i]);
if(quer(l[0].size(), tb.size(), l[0], tb)) ta=l[0];
else ta=l[1];
}
while(tb.size()>1){
vc<ll> l[2];
loop(i, 0, tb.size()) l[i%2].ps(tb[i]);
if(quer(l[0].size(), ta.size(), l[0], ta)) tb=l[0];
else tb=l[1];
}
return make_pair(ta[0], tb[0]);
}
void run(ll n){
loop(i, 1, n+1) dsu.ps(vc<ll> {i});
loop(i, 0, n-1){
pa ans=solve();
ll a, b;vc<ll> temp;
loop(i, 0, dsu.size()) fore(u, dsu[i]) if(u==ans.fi) a=i;
fore(v, dsu[a]) temp.ps(v);
dsu.erase(dsu.begin()+a);
loop(i, 0, dsu.size()) fore(u, dsu[i]) if(u==ans.se) b=i;
fore(v, dsu[b]) temp.ps(v);
dsu.erase(dsu.begin()+b);
dsu.ps(temp);
setRoad(ans.fi, ans.se);
}
}
Compilation message
icc.cpp: In function 'std::pair<long long int, long long int> solve()':
icc.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
79 | loop(i, 0, fa.size()) l[i%2].ps(fa[i]);
| ~~~~~~~~~~~~~~~
icc.cpp:79:9: note: in expansion of macro 'loop'
79 | loop(i, 0, fa.size()) l[i%2].ps(fa[i]);
| ^~~~
icc.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
85 | loop(i, 0, fb.size()) l[i%2].ps(fb[i]);
| ~~~~~~~~~~~~~~~
icc.cpp:85:9: note: in expansion of macro 'loop'
85 | loop(i, 0, fb.size()) l[i%2].ps(fb[i]);
| ^~~~
icc.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
92 | loop(i, 0, ta.size()) l[i%2].ps(ta[i]);
| ~~~~~~~~~~~~~~~
icc.cpp:92:9: note: in expansion of macro 'loop'
92 | loop(i, 0, ta.size()) l[i%2].ps(ta[i]);
| ^~~~
icc.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
98 | loop(i, 0, tb.size()) l[i%2].ps(tb[i]);
| ~~~~~~~~~~~~~~~
icc.cpp:98:9: note: in expansion of macro 'loop'
98 | loop(i, 0, tb.size()) l[i%2].ps(tb[i]);
| ^~~~
icc.cpp: In function 'void run(long long int)':
icc.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
109 | loop(i, 0, dsu.size()) fore(u, dsu[i]) if(u==ans.fi) a=i;
| ~~~~~~~~~~~~~~~~
icc.cpp:109:9: note: in expansion of macro 'loop'
109 | loop(i, 0, dsu.size()) fore(u, dsu[i]) if(u==ans.fi) a=i;
| ^~~~
icc.cpp:3:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define loop(i, a, b) for(long long i=a;i<b;i++)
......
113 | loop(i, 0, dsu.size()) fore(u, dsu[i]) if(u==ans.se) b=i;
| ~~~~~~~~~~~~~~~~
icc.cpp:113:9: note: in expansion of macro 'loop'
113 | loop(i, 0, dsu.size()) fore(u, dsu[i]) if(u==ans.se) b=i;
| ^~~~
icc.cpp:114:22: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
114 | fore(v, dsu[b]) temp.ps(v);
| ^
icc.cpp:110:22: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
110 | fore(v, dsu[a]) temp.ps(v);
| ^
/tmp/ccQ8qmig.o: In function `main':
grader.cpp:(.text.startup+0x1d): undefined reference to `run'
collect2: error: ld returned 1 exit status