제출 #476316

#제출 시각아이디문제언어결과실행 시간메모리
476316Mackerel_Pike3D Histogram (COCI20_histogram)C++14
0 / 110
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n; int a[maxn], b[maxn], f[maxn], g[maxn]; long long ans; inline void calc(int l, int r, int ql, int qr){ if(l > r) return; int md = l + r >> 1, pos = -1; long long ret = 0; for(int i = ql; i <= qr; ++i){ long long res = 1ll * (i - md + 1) * min(f[md], f[i]) * min(g[md], g[i]); if(!~pos || res > ret) ret = res, pos = i; } ans = max(ans, ret); calc(l, md - 1, pos, qr); calc(md + 1, r, ql, pos); return; } inline void solve(int l, int r){ if(l == r){ ans = max(ans, 1ll * a[l] * b[l]); return; } int md = l + r >> 1; for(int i = md; i >= l; --i){ f[i] = min(i == md ? 0x3f3f3f3f : f[i + 1], a[i]); g[i] = min(i == md ? 0x3f3f3f3f : g[i + 1], b[i]); } for(int i = md + 1; i <= r; ++i){ f[i] = min(i == md + 1 ? 0x3f3f3f3f : f[i - 1], a[i]); g[i] = min(i == md + 1 ? 0x3f3f3f3f : g[i - 1], b[i]); } calc(l, md, md + 1, r); solve(l, md), solve(md + 1, r); return; } int main(){ //freopen("histogram.in.1a", "r", stdin); scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%d%d", a + i, b + i); solve(0, n - 1); printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

histogram.cpp: In function 'void calc(int, int, int, int)':
histogram.cpp:14:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |   int md = l + r >> 1, pos = -1;
      |            ~~^~~
histogram.cpp: In function 'void solve(int, int)':
histogram.cpp:32:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |   int md = l + r >> 1;
      |            ~~^~~
histogram.cpp: In function 'int main()':
histogram.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
histogram.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d%d", a + i, b + i);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...