이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#include "ricehub.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,pref[200005],suf[200005],a[200005];
ll calc1(ll i,ll j){
return pref[j]-pref[i]-i*(a[j]-a[i]);
}
ll calc2(ll i,ll j){
return suf[i]-suf[j]-(n-(j+1))*(a[j]-a[i]);
}
int32_t besthub(int32_t R,int32_t L,int32_t X[],ll B){
n=R;
for(ll i=0;i<n;i++)
{
a[i]=X[i];
if(i>0){
pref[i]=pref[i-1]+i*(a[i]-a[i-1]);
}
}
for(ll i=n-1;i>=0;i--)
{
if(i<n-1){
suf[i]=suf[i+1]+(n-(i+1))*(a[i+1]-a[i]);
}
}
ll ans=1;
for(ll i=0;i<n;i++){
ll l=0,r=n+1,mid=(l+r)>>1ll;
while(l<r){
ll mid=(l+r)>>1ll,x=0,y=0;
if(mid%2==1){
x=mid>>1ll;
y=mid>>1ll;
}else {
y=mid>>1ll;
x=(mid>>1ll)-1;
}
if((x>i)||(y>(n-(i+1)))){
r=mid;
continue;
}
ll sum=calc1(i-x,i)+calc2(i,i+y);
if(sum>B){
r=mid;
}else {
l=mid+1;
}
mid=(l+r)>>1ll;
}
ll x=0,y=0;
if(mid%2==1){
x=mid>>1ll;
y=mid>>1ll;
}else {
y=mid>>1ll;
x=(mid>>1ll)-1;
}
ll sum=calc1(max(0ll,i-x),i)+calc2(i,i+y);
if(sum>B||x>i||y>(n-(i+1))){
mid--;
}
ans=max(ans,mid);
}
return ans;
}
/*
int32_t main(){
CODE_START;
*/
# | 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... |