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 "ricehub.h"
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define os tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
#define inr int32_t
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
inr besthub(inr R, inr L, inr X[], long long B)
{
vi p(R+1,0);
for (int i=1;i<=R;i++) p[i] = p[i-1]+X[i-1];
int l = 1;
int r = R;
while (l<=r) {
int m = (l+r) >> 1;
os oset;
for (int j=1;j<=m-1;j++) {
oset.insert({X[j-1],j-1});
}
bool fl = 0;
for (int j=m;j<=R;j++) {
oset.insert({X[j-1],j});
int med = oset.find_by_order(m/2)->first;
int medidx = j-m+m/2+1;
int sag = (p[j]-p[medidx-1])-med*(j-medidx+1);
int sol = med*(medidx-(j-m+1)+1)-(p[medidx]-p[j-m]);
if(sol+sag <= B) fl = 1;
oset.erase(oset.begin());
}
if (fl) l = m+1;
else r = m-1;
}
return r;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |