This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T& a, string separator = " ", string finish = "\n"){
for(auto i: a) cout << i << separator;
cout << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
// namespace Interactor{
// const int BLOCK = 400;
// int n;
// vector<int> a;
// vector<int> ask(int i){
// vector<int> ans(2);
// for(int j = 0; j < i; ++j) ans[0] += (a[j] < a[i]);
// for(int j = i+1; j<n; ++j) ans[1] += (a[j] < a[i]);
// return ans;
// }
int range_query(set<int> &S, int l, int r){
auto it = S.lower_bound(l);
int cnt = 0;
while(it != S.end()){
if (*it > r) break;
cnt++;
it++;
}
return cnt;
}
void DnC(int l, int r, int ma, vector<pair<int, int>> &b, set<int> &S1, set<int> &S2){
if (l > r) return;
int x = (l + r) >> 1;
if (b[x].first == -1){
vector<int> cur= ask(x);
b[x] = {cur[0], cur[1]};
}
if (b[x].first + b[x].second == ma){
S1.insert(x);
// look to the left
auto it = S1.lower_bound(x); it--;
int dL = b[x].first - b[*it].first;
if (dL - range_query(S2, *it, x) > 0) DnC(l, x - 1, ma, b, S1, S2);
// look to the right
it = S1.upper_bound(x);
if (it == S1.end()) {
DnC(x + 1, r, ma, b, S1, S2);
return;
}
dL = b[*it].first - b[x].first;
if (dL - range_query(S2, x, *it) > 0) DnC(x + 1, r, ma, b, S1, S2);
}
else{
S2.insert(x);
DnC(l, x - 1, ma, b, S1, S2);
DnC(x + 1, r, ma, b, S1, S2);
}
}
int find_best(int n) {
const int BLOCK = 450;
vector<pair<int, int>> b(n, {-1, -1});
if (n <= 1e4){
for(int i = 0; i<n; ++i) {
vector<int> cur = ask(i);
if (cur[0] + cur[1] == 0) return i;
}
}
int ma = 0;
for(int i = 0; i<BLOCK; ++i){
vector<int> cur = ask(i);
b[i] = {cur[0], cur[1]};
maximize(ma, cur[0] + cur[1]);
}
set<int> S1, S2;
for(int i = 0; i<BLOCK; ++i){
if (b[i].first + b[i].second == ma) S1.insert(i);
else S2.insert(i);
}
DnC(BLOCK, n-1, ma, b, S1, S2);
for(int i: S2) if (b[i].first + b[i].second == 0) return i;
return -1;
}
// bool solve(){
// n = 2e5;
// a.resize(n, 3);
// a[0] = 1;
// for(int i = 1; i<=BLOCK; ++i) a[i] = 2;
// // reverse(ALL(a));
// shuffle(ALL(a), rng);
// // printArr(a, "");
// int j = find_best(n);
// cout << "! " << j << "\n";
// return a[j] == 1;
// }
// }
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// bool verdict = Interactor::solve();
// if (verdict) cout << "AC\n";
// else cout << "WA\n";
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |