#include "insects.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
int min_cardinality(int n)
{
random_start();
vi nums;
rep(i,n) nums.pb(i);
shuffle(all(nums),mt);
int P = 0;
set<int> cur_in;
set<int> not_add;
forall(it,nums)
{
move_inside(it);
if(press_button() == 2)
{
move_outside(it);
}
else
{
P++;
cur_in.insert(it);
}
}
int l = 1;
int r = n/P;
int ans = 1;
while(l <= r)
{
int mid = (l+r)/2;
vi new_ = {};
vi new_del = {};
forall(it,nums)
{
if(mid * P == siz(cur_in)) break;
if(cur_in.find(it) == cur_in.end() && not_add.find(it) == not_add.end())
{
move_inside(it);
cur_in.insert(it);
if(press_button() <= mid)
{
new_.pb(it);
}
else
{
move_outside(it);
cur_in.erase(cur_in.find(it));
new_del.pb(it);
}
}
}
if(mid*P == siz(cur_in))
{
ans = mid;
l = mid+1;
forall(it,new_del) not_add.insert(it);
forall(it,new_)
{
move_outside(it);
cur_in.erase(cur_in.find(it));
}
}
else
{
r = mid-1;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |