Submission #116145

#TimeUsernameProblemLanguageResultExecution timeMemory
116145RezwanArefin01Holiday (IOI14_holiday)C++17
0 / 100
37 ms8704 KiB
#include <bits/stdc++.h> #include "holiday.h" using namespace std; typedef long long ll; const int N = 1e5 + 10; int pos[N], p[N]; struct Node { ll sum; int cnt; Node(int sum = 0, int cnt = 0) : sum(sum), cnt(cnt) {} } t[N << 2]; Node merge(Node a, Node b) { return Node(a.sum + b.sum, a.cnt + b.cnt); } void update(int node, int l, int r, int i, int x) { if(l == r) { t[node] = Node(x, 1); return; } int m = l + r >> 1; if(i <= m) update(node << 1, l, m, i, x); else update(node << 1 | 1, m + 1, r, i, x); t[node] = merge(t[node << 1], t[node << 1 | 1]); } ll query(int node, int l, int r, int k) { if(l == r) return k ? t[node].sum : 0; int m = l + r >> 1; if(t[node << 1].cnt >= k) return query(node << 1, l, m, k); else return query(node << 1 | 1, m + 1, r, k - t[node << 1].cnt) + t[node << 1].sum; } ll findMaxAttraction(int n, int start, int d, int a[]) { iota(p, p + n, 0); sort(p, p + n, [&](int i, int j) { return a[i] > a[j]; }); for(int i = 0; i < n; ++i) pos[p[i]] = i; ll ans = 0; for(int i = 0; i < n; ++i) { if(i > d) break; update(1, 1, n, pos[i], a[i]); ans = max(ans, query(1, 1, n, d - i)); } return ans; }

Compilation message (stderr)

holiday.cpp: In function 'void update(int, int, int, int, int)':
holiday.cpp:22:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1; 
             ~~^~~
holiday.cpp: In function 'll query(int, int, int, int)':
holiday.cpp:30:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l + r >> 1;
             ~~^~~
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
     int i, n_s;
            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...