Submission #729539

#TimeUsernameProblemLanguageResultExecution timeMemory
729539hoainiemRice Hub (IOI11_ricehub)C++14
0 / 100
13 ms1032 KiB
#include <bits/stdc++.h> #include "ricehub.h" #define lc id<<1 #define rc id<<1^1 #define nmax 100008 using namespace std; int n, mx, ans = 0, a[nmax]; long long k; struct segtree{ long long seg[nmax << 2]; void build(int id = 1, int l = 1, int r = n){ if (l == r){ seg[id] = a[l]; return; } int mid = (l + r) >> 1; build(lc, l, mid); build(rc, mid + 1, r); seg[id] = seg[lc] - seg[rc]; } long long get(int u, int v, int id = 1, int l = 1, int r = n){ if (r < u || l > v) return 0; if (u <= l && r <= v) return seg[id]; int mid = (l + r) >> 1; return get(u, v, lc, l, mid) + get(u, v, rc, mid + 1, r); } }tree; long long cost(int l, int r){ if (l == r) return 0; int mid = (l + r) >> 1; return 1LL * a[mid] * (mid - l + 1) - tree.get(l, mid) + tree.get(mid + 1, r) - 1LL * a[mid] * (r - mid); } int besthub(int R, int L, int X[], long long B){ n = R; mx = L; k = B; for (int i = 1; i <= n; i++) a[i] = X[i - 1]; tree.build(); for (int i = 1, j = 1; i <= n; i++){ while (cost(j, i) > B) j++; ans = max(ans, i - j + 1); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...