Submission #339483

#TimeUsernameProblemLanguageResultExecution timeMemory
339483bigDuckRice Hub (IOI11_ricehub)C++14
100 / 100
25 ms3124 KiB
#include "ricehub.h" #include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int d1[100010], d2[100010]; int x[100010], n; int sum1(int i, int j){ return d1[j]-d1[i]-(i)*(x[j]-x[i]); } int sum2(int i, int j){ return d2[i]-d2[j]-(n-j-1)*(x[j]-x[i]); } int32_t besthub(int32_t R, int32_t L, int32_t X[], long long B) { n=R; for(int i=0; i<R; i++){ x[i]=X[i]; if(i>0){ d1[i]=d1[i-1]+(i)*(x[i]-x[i-1]); } } for(int i=R-1; i>=0; i--){ if(i<(R-1)){ d2[i]=d2[i+1]+(n-(i+1))*(x[i+1]-x[i]); } } int res=1; for(int i=0; i<R; i++){ int l=0, r=R+1, m=(l+r)>>1ll; while(l<r){ m=(l+r)>>1ll; int lt=0, rt=0; if( (m%2)==1){ lt=m>>1ll; rt=m>>1ll; } else{ rt=m>>1ll; lt=(m>>1ll)-1; } if( (lt>(i)) || (rt>(R-(i+1))) ){ r=m; continue; } int sum=sum1(i-lt, i)+sum2(i, i+rt); if(sum>B){ r=m; } else{ l=(m+1); } m=(l+r)>>1ll; } int lt=0, rt=0; if( (m%2)==1){ lt=m>>1ll; rt=m>>1ll; } else{ rt=m>>1ll; lt=(m>>1ll)-1; } int sum=sum1(max(i-lt, 0ll), i)+sum2(i, i+rt); if( (sum>B) || (lt>(i)) || (rt>(R-(i+1))) ){ m--; } res=max(res, m); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...