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"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pi pair<int,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
#define int ll
struct BIT {
vector<int> t; int n;
BIT(int n) {
this->n=n;
t.assign(n,0);
}
void add(int i, int x) {
for(;i<n;i=i|(i+1)) t[i]+=x;
}
int sum(int r) {
int q=0;
for(;r>=0;r=(r&(r+1))-1) q+=t[r];
return q;
}
int sum(int l, int r) {
return sum(r)-sum(l-1);
}
};
#undef int
int besthub(int n, int L, int x[], ll b) {
#define int ll
BIT ft(n);
forn(i,n) ft.add(i,x[i]);
int l=1, r=n;
while (l<r) {
int m=(l+r+1)>>1;
ll mn=1e18;
for (int i=0; i+m<=n; ++i) {
int t = (i+m/2);
ll z = 1ll*x[t]*(t-i+1)-ft.sum(i,t) + ft.sum(t,i+m-1)-1ll*(i+m-t)*x[t];
mn=min(mn,z);
}
if (mn>b) r=m-1;
else l=m;
}
return r;
#undef int
}
# | 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... |