Submission #476314

# Submission time Handle Problem Language Result Execution time Memory
476314 2021-09-26T03:03:42 Z Mackerel_Pike 3D Histogram (COCI20_histogram) C++14
0 / 110
2 ms 332 KB
#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 * (md - pos + 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, ql, pos);
  calc(md + 1, r, pos + 1, qr);
  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", "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;
}

Compilation message

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 time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -