Submission #727891

#TimeUsernameProblemLanguageResultExecution timeMemory
727891He_HuangluHoliday (IOI14_holiday)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 5, maxn = 100; int n, st, d, a[N]; long long res; struct node { int sum; long long val; node *left, *right; node () { sum = 0, val = 0; left = right = nullptr; } }; node *t[N]; int sum(node *p) { return p ? p->sum : 0; } long long val(node *p) { return p ? p->val : 0; } void upd(node *x, int l, int r, int pos) { if(l == r) { x->sum += 1; x->val += pos; return ; } int mid = l + r >> 1; if(pos <= mid) { x->left = x->left ? new node(*x->left) : new node(); upd(x->left, l, mid, pos); } else { x->right = x->right ? new node(*x->right) : new node(); upd(x->right, mid + 1, r, pos); } x->sum = sum(x->left) + sum(x->right); x->val = val(x->left) + val(x->right); } long long get(node *xl, node *xr, int l, int r, int k) { if(l == r) return l * min(k, sum(xr) - sum(xl)); int mid = l + r >> 1; int cnt = sum(xr->right) - sum(xl->right); if(cnt > k) { xl->right = xl->right ? new node(*xl->right) : new node(); xr->right = xr->right ? new node(*xr->right) : new node(); return get(xl->right, xr->right, mid + 1, r, k); } else { xl->left = xl->left ? new node(*xl->left) : new node(); xr->left = xr->left ? new node(*xr->left) : new node(); return val(xr->right) - val(xl->right) + get(xl->left, xr->left, l, mid, k - cnt); } } long long cost(int l, int r) { int k = d - (r - l + min(st - l, r - st)); if(k <= 0) return 0; return get(t[l - 1], t[r], 0, maxn, min(k, r - l + 1)); } void solve(int l, int r, int optl, int optr) { if(l > r) return ; int mid = l + r >> 1; pair <long long, int> best = {-1, 0}; for(int i = optl; i <= min(mid, optr); i++) { best = max(best, {cost(i, mid), i}); } res = max(res, best.first); solve(l, mid - 1, optl, best.second); solve(mid + 1, r, best.second, optr); } long long findMaxAttraction(int N, int Start, int D, int a[]) { t[0] = new node(); n = N, d = D, st = Start + 1; for(int i = 1; i <= n; i++) { t[i] = new node(*t[i - 1]); upd(t[i], 0, maxn, a[i - 1]); } solve(st, n, 1, st); return res; } //main () { // cin.tie(0)->sync_with_stdio(0); // if(fopen("task.inp", "r")) { // freopen("task.inp", "r", stdin); // freopen("wa.out", "w", stdout); // } // cin >> n >> st >> d; // for(int i = 0; i < n; i++) cin >> a[i]; // cout << findMaxAttraction(n, st, d, a); //}

Compilation message (stderr)

holiday.cpp: In function 'void upd(node*, long long int, long long int, long long int)':
holiday.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = l + r >> 1;
      |               ~~^~~
holiday.cpp: In function 'long long int get(node*, node*, long long int, long long int, long long int)':
holiday.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |     int mid = l + r >> 1;
      |               ~~^~~
holiday.cpp: In function 'void solve(long long int, long long int, long long int, long long int)':
holiday.cpp:70:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |     int mid = l + r >> 1;
      |               ~~^~~
/usr/bin/ld: /tmp/cc5i3BnW.o: in function `main':
grader.cpp:(.text.startup+0xaf): undefined reference to `findMaxAttraction(int, int, int, int*)'
collect2: error: ld returned 1 exit status