Submission #44051

#TimeUsernameProblemLanguageResultExecution timeMemory
44051wxh010910Candies (JOI18_candies)C++17
100 / 100
164 ms9276 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back #define Debug(...) fprintf(stderr, __VA_ARGS__) typedef long long LL; typedef long double LD; typedef unsigned int uint; typedef pair <int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } template <typename T> inline bool CheckMax(T &a, const T &b) { return a < b ? a = b, true : false; } template <typename T> inline bool CheckMin(T &a, const T &b) { return a > b ? a = b, true : false; } const int N = 200005; const LL inf = 1LL << 60; priority_queue <pair <LL, int>> q; int n, nxt[N], pre[N]; LL ans, a[N]; int main() { #ifdef wxh010910 freopen("d.in", "r", stdin); #endif Read(n); for (int i = 1; i <= n; ++i) { Read(a[i]), pre[i] = i - 1, nxt[i] = i + 1; q.push(mp(a[i], i)); } nxt[n] = 0; for (int i = 1; i <= n + 1 >> 1; ++i) { for (; q.top().X != a[q.top().Y]; q.pop()); int x = q.top().Y, l = pre[x], r = nxt[x]; printf("%lld\n", ans += a[x]), q.pop(); pre[nxt[x] = nxt[r]] = x, nxt[pre[x] = pre[l]] = x; a[x] = l && r ? max(-inf, a[l] + a[r] - a[x]) : -inf, a[l] = a[r] = -inf; q.push(mp(a[x], x)); } #ifdef wxh010910 Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif return 0; }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:58:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   for (int i = 1; i <= n + 1 >> 1; ++i) {
                        ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...