#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "mushrooms.h"
int sum = 0;
int use_machine(int l, int r) {
sum += r-l+1;
/*cout << "use_machine(" << l << ", " << r << ")" << endl;*/
VI a;
replr(i, l, r) a.pb(i);
return use_machine(a);
}
int count_mushrooms(int n) {
auto binsearch = [&](int L, int R) {
// searching for the first index i
// such that a[i] != a[L] and i is
// in range [L+1, R]
// return R+1 if no such index
setmin(R, n-1);
/*cout << "BINSEARCH(" << L << ", " << R << ")";*/
int l = L, r = R+1;
while (l + 1 < r) {
int m = (l + r) / 2;
if (use_machine(l, m)) r = m;
else l = m;
}
/*cout << " = " << r << endl;*/
return r;
};
int sq = max(1, int(sqrt(n))/2);
VI dif(n+1);
int L = 0;
while (L < n) {
int ret = binsearch(L, L + sq);
if (ret == L+sq+1) {
/*cout << "SO THERE IS A CHANGE AT INDEX " << ret << endl;*/
L = L + sq;
} else {
L = ret;
dif[ret] = 1;
}
}
VI ans(n);
int cur = 0;
rep(i, n) {
if (dif[i]) cur = !cur;
ans[i] = cur;
}
/*for (int x : ans) cout << x << " ";*/
/*cout << endl;*/
cout << sum << endl;
int ret = 0;
for (int x : ans) ret += !x;
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
0 ms |
344 KB |
Invalid action (protocol error). |
2 |
Halted |
0 ms |
0 KB |
- |