Submission #141098

#TimeUsernameProblemLanguageResultExecution timeMemory
141098abacabaLightning Conductor (POI11_pio)C++14
0 / 100
1069 ms19916 KiB
#include <bits/stdc++.h> using namespace std; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> const int inf = 2e9; const int N = 1e6 + 15; int n, a[N], k, f[N]; pii t[N << 4]; void build(int v, int tl, int tr, int keep = -1) { if(tl == tr) { t[v] = {a[tl], keep * tl}; return; } int mid = tl + tr >> 1; build(v << 1, tl, mid, keep); build(v << 1 | 1, mid + 1, tr, keep); t[v] = max(t[v << 1], t[v << 1 | 1]); } pii get(int v, int tl, int tr, int l, int r) { if(tl > r || tr < l) return {-inf, -inf}; if(tl >= l && tr <= r) return t[v]; int mid = tl + tr >> 1; return max(get(v << 1, tl, mid, l, r), get(v << 1 | 1, mid + 1, tr, l, r)); } int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); build(1, 1, n); for(int i = 2; i <= n; ++i) { pii now = get(1, 1, n, 1, i - 1); int hj = now.f, sqr = ceil(sqrt(i + now.se)); f[i] = hj + sqr - a[i]; } build(1, 1, n, 1); for(int i = n - 1; i; --i) { pii now = get(1, 1, n, i + 1, n); int hj = now.f, sqr = ceil(sqrt(now.se - i)); f[i] = max(f[i], hj + sqr - a[i]); } for(int i = 1; i <= n; ++i) cout << f[i] << endl; return 0; }

Compilation message (stderr)

pio.cpp: In function 'void build(int, int, int, int)':
pio.cpp:30:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1;
               ~~~^~~~
pio.cpp: In function 'std::pair<int, int> get(int, int, int, int, int)':
pio.cpp:41:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1;
               ~~~^~~~
pio.cpp: In function 'int main()':
pio.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
pio.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...