Submission #440306

# Submission time Handle Problem Language Result Execution time Memory
440306 2021-07-02T02:14:18 Z nguot 3D Histogram (COCI20_histogram) C++14
0 / 110
2 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fori(x,a,b) for(int x=a;x<=b;x++)
#define ford(x,a,b) for(int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);

const int N = 2e5 + 10;
int l[N],r[N],s[4*N],a[N],b[N],n;
void build(int x,int l,int r)
{
    if(l==r)
    {
        s[x] = b[l];
        return;
    }
    int mid = (l+r)/2;
    build(2*x,l,mid);build(2*x+1,mid+1,r);
    s[x] = min(s[2*x],s[2*x+1]);
}

int get(int x,int l,int r,int u,int v)
{
   if(l==u&&r==v) return s[x];
   int mid = (l+r)/2;
   if(v<=mid) return get(2*x,l,mid,u,v);
   else if(u>=mid+1) return get(2*x+1,mid+1,r,u,v);
   return min(get(2*x,l,mid,u,mid),get(2*x+1,mid+1,r,mid+1,v));
}
main()
{
    //freopen("task.inp","r",stdin);
    fasty;
   cin>>n;
   fori(i,1,n) cin>>a[i]>>b[i];
   build(1,1,n);
   stack<int> st;
   fori(i,1,n)
   {
       while(!st.empty() && a[st.top()]>=a[i]) st.pop();
       if(st.empty()) l[i] = 0;
       else l[i] = st.top();
       st.push(i);
   }
   while(!st.empty()) st.pop();
   ford(i,n,1)
   {
       while(!st.empty() && a[st.top()]>=a[i]) st.pop();
       if(st.empty()) r[i] = n+1;
       else r[i] = st.top();
       st.push(i);
   }

   ll kq = 0;
   fori(i,1,n)
   {
       int len = get(1,1,n,l[i]+1,r[i]-1);
       kq=max(kq,1ll*(r[i]-l[i]-1)*1ll*len*1ll*a[i]);
   }
   cout<<kq;
}
//50
//usaco guide PLATINUM,oiwiki
//https://codeforces.com/blog/entry/92130
/* Weak:
- Lien Thong Manh(https://codeforces.com/blog/entry/68138,1534F1,1027F,usaco)
- Constructive(https://assets.hkoi.org/training2018/ca.pdf,https://codeforces.com/blog/entry/69575?)
- Flow
- Geometry(cses (Errichto),Line sweep) (MPOLY,CVXPOLY,MTRIAREA)
- HLD(https://codeforces.com/blog/entry/81317,Negativez2(E.Tourist))
*/

Compilation message

histogram.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -