#include "chameleon.h"
#include "bits/stdc++.h"
using namespace std;
namespace {
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
// inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
// string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
typedef int ll;
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;
#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (1006)
vector<int> v[MAXN];
int colour[MAXN], out[MAXN], in[MAXN];
bitset<MAXN> match;
} // namespace
void Solve(int n) {
vector<vector<int>> C(2, vector<int>());
auto get_from=[&](ll b,ll s,ll e){
vector<int> res;
FOR(i,s,e) res.pb(C[b][i]);
return res;
};
auto concat=[&](vector<int> v, int x){
v.pb(x);
return v;
};
ll ls_0=0, ls_1=0;
auto get_sz=[&](ll b){
return siz(C[b]) - (b?ls_1:ls_0);
};
auto add_edge=[&](ll a,ll b){ return v[a].eb(b), v[b].eb(a); };
auto solve=[&](ll b,ll x){
ll st=(b?ls_1:ls_0)-1, en=siz(C[b]);
// minimum pos such that become <= same
while(en-st>1){
ll mid=(st+en)>>1;
if(Query(concat(get_from(b,(b?ls_1:ls_0),mid),x))<=mid-(b?ls_1:ls_0)+1) en=mid;
else st=mid;
}
assert(en^siz(C[b]));
add_edge(x, C[b][en]);
return en;
};
n*=2;
FOR(i,1,n){
ls_0=ls_1=0;
FOR(ii,1,3){
ll a=Query(concat(get_from(0,ls_0,siz(C[0])-1), i)),b=Query(concat(get_from(1,ls_1,siz(C[1])-1), i));
if(a > get_sz(0) && b > get_sz(1)) break;
if(a<=get_sz(0)){
ls_0=solve(0,i)+1;
}else if(b<=get_sz(1)){
ls_1=solve(1,i)+1;
}
}
mmst(colour,-1), C[0].clear(), C[1].clear();
function<void(ll)>dfs=[&](ll x){
for(auto i:v[x]) if(colour[i]==-1){
colour[i]=colour[x]^1;
dfs(i);
}else assert(colour[i]==!colour[x]);
};
FOR(j,1,i)if(colour[j]==-1){
colour[j]=0, dfs(j);
}
FOR(j,1,i) C[colour[j]].pb(j);
}
assert(C[0].size()==n/2&&C[1].size()==n/2);
FOR(i,1,n){
if(v[i].size()==1){
if(match[i])continue;
match[i]=match[v[i][0]]=1;
Answer(i, v[i][0]);
}else{
assert(v[i].size()==3);
ll a=v[i][0], b=v[i][1], c=v[i][2];
ll ab=Query(vector<ll>()={a,b,i});
ll ac=Query(vector<ll>()={a,c,i});
ll bc=Query(vector<ll>()={b,c,i});
if(ab==1) { // c is x's out
out[i]=c, in[c]=i;
}else if(ac==1) { // is b
out[i]=b, in[b]=i;
}else if(bc==1) { // is a
out[i]=a, in[a]=i;
}else assert(0);
}
}
FOR(i,1,n)if(match[i]==0){
v[i].erase(find(all(v[i]), out[i]));
v[i].erase(find(all(v[i]), in[i]));
assert(v[i].size()==1);
match[i]=match[v[i][0]]=1;
Answer(i, v[i][0]);
}
return;
}
Compilation message
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from chameleon.cpp:2:
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(C[0].size()==n/2&&C[1].size()==n/2);
~~~~~~~~~~~^~~~~
chameleon.cpp:89:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(C[0].size()==n/2&&C[1].size()==n/2);
~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
47 ms |
384 KB |
Output is correct |
4 |
Correct |
47 ms |
384 KB |
Output is correct |
5 |
Correct |
50 ms |
384 KB |
Output is correct |
6 |
Correct |
47 ms |
456 KB |
Output is correct |
7 |
Correct |
48 ms |
384 KB |
Output is correct |
8 |
Correct |
82 ms |
384 KB |
Output is correct |
9 |
Correct |
47 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
432 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
79 ms |
480 KB |
Output is correct |
4 |
Correct |
76 ms |
504 KB |
Output is correct |
5 |
Correct |
79 ms |
504 KB |
Output is correct |
6 |
Correct |
77 ms |
504 KB |
Output is correct |
7 |
Correct |
76 ms |
508 KB |
Output is correct |
8 |
Correct |
80 ms |
632 KB |
Output is correct |
9 |
Correct |
80 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
47 ms |
384 KB |
Output is correct |
4 |
Correct |
47 ms |
384 KB |
Output is correct |
5 |
Correct |
50 ms |
384 KB |
Output is correct |
6 |
Correct |
47 ms |
456 KB |
Output is correct |
7 |
Correct |
48 ms |
384 KB |
Output is correct |
8 |
Correct |
82 ms |
384 KB |
Output is correct |
9 |
Correct |
47 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
432 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
6 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
79 ms |
480 KB |
Output is correct |
31 |
Correct |
76 ms |
504 KB |
Output is correct |
32 |
Correct |
79 ms |
504 KB |
Output is correct |
33 |
Correct |
77 ms |
504 KB |
Output is correct |
34 |
Correct |
76 ms |
508 KB |
Output is correct |
35 |
Correct |
80 ms |
632 KB |
Output is correct |
36 |
Correct |
80 ms |
504 KB |
Output is correct |
37 |
Correct |
77 ms |
496 KB |
Output is correct |
38 |
Correct |
48 ms |
384 KB |
Output is correct |
39 |
Correct |
78 ms |
472 KB |
Output is correct |
40 |
Correct |
87 ms |
540 KB |
Output is correct |
41 |
Correct |
80 ms |
504 KB |
Output is correct |
42 |
Correct |
47 ms |
384 KB |
Output is correct |
43 |
Correct |
76 ms |
508 KB |
Output is correct |
44 |
Correct |
81 ms |
504 KB |
Output is correct |
45 |
Correct |
80 ms |
508 KB |
Output is correct |