#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
vector<int> a;
int tot,cnt,n;
void add(int x){tot++; move_inside(x);}
void del(int x){tot--; move_outside(x);}
int ask(){ return press_button();}
/* a[i]=-2 temp added, a[i]=-1 temp over, a[i]=0 over, a[i]=1 first meet, a[i]=2 repeat*/
bool check(int x){
int sz=cnt;
for(int i=0;i<n;i++){
if(a[i]==1 || a[i]==0) continue;
add(i); sz++; a[i]=-2;
if(ask()>x){del(i); a[i]=-1;sz--;}
}
if(cnt*x==sz){//答案可以接受需要rollback所有操作
for(int i=0;i<n;i++){
if(a[i]==-2){ del(i); a[i]=2;}
if(a[i]==-1){ a[i]=2;}
}
return true;
}
else{
for(int i=0;i<n;i++){
if(a[i]==-2){ del(i); a[i]=2;}
if(a[i]==-1) a[i]=0;
}
return false;
}
}
int min_cardinality(int N) {
n=N;
a.assign(n,2);
for(int i=0;i<n;i++){ add(i); if(ask()>1) del(i); else a[i]=1,cnt++;}
int l=1,r=n/cnt,res=n+1;
while(l<r){
int mid=(l+r)>>1;
if(check(mid)){ res=mid; l=mid+1;}
else r=mid-1;
}
return res;
}
Compilation message
insects.cpp: In function 'void add(int)':
insects.cpp:14:24: error: 'move_inside' was not declared in this scope
14 | void add(int x){tot++; move_inside(x);}
| ^~~~~~~~~~~
insects.cpp: In function 'void del(int)':
insects.cpp:15:24: error: 'move_outside' was not declared in this scope
15 | void del(int x){tot--; move_outside(x);}
| ^~~~~~~~~~~~
insects.cpp: In function 'int ask()':
insects.cpp:16:19: error: 'press_button' was not declared in this scope
16 | int ask(){ return press_button();}
| ^~~~~~~~~~~~