Submission #776898

#TimeUsernameProblemLanguageResultExecution timeMemory
776898I_Love_EliskaM_Rice Hub (IOI11_ricehub)C++14
100 / 100
31 ms2560 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...