Submission #729559

#TimeUsernameProblemLanguageResultExecution timeMemory
729559hoainiemRice Hub (IOI11_ricehub)C++14
100 / 100
44 ms4236 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; int xx = tree.get(l, mid); int yy = tree.get(mid + 1, r); 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; }

Compilation message (stderr)

ricehub.cpp: In function 'long long int cost(int, int)':
ricehub.cpp:34:9: warning: unused variable 'xx' [-Wunused-variable]
   34 |     int xx = tree.get(l, mid);
      |         ^~
ricehub.cpp:35:9: warning: unused variable 'yy' [-Wunused-variable]
   35 |     int yy = tree.get(mid + 1, r);
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...