Submission #503057

# Submission time Handle Problem Language Result Execution time Memory
503057 2022-01-07T04:40:30 Z zaneyu 3D Histogram (COCI20_histogram) C++14
20 / 110
846 ms 475100 KB
/*input
6
3 1
2 1
2 2
2 3
1 1
2 2
*/
#include<bits/stdc++.h>
#include <nmmintrin.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?"\n":"");
    return out;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    a%=MOD;
    if(a==0) return 0;
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
int a[maxn],b[maxn];
ll ans=0;
int sa[maxn],sb[maxn];
struct line{
    ll m,c;
    ll eval(ll x){
        return m*x+c;
    }
    ld intersect(line x){
        return (ld)(x.c-c)/(m-x.m);
    }
}; //beware of same slope
struct cht{
    deque<line> dq;
    void add(line z){
        //CHECK THIS
        if(sz(dq) and dq.back().m==z.m) return;
        while(sz(dq)>=2 and dq.back().intersect(dq[sz(dq)-2])>=dq[sz(dq)-2].intersect(z)){
            dq.pop_back();
        }
        dq.pb(z);
    }
    ll query(ll x){
        assert(sz(dq));
        while(sz(dq)>=2 and dq[0].eval(x)<=dq[1].eval(x)) dq.pop_front();
        return dq[0].eval(x);
    }
}seg[700000];
void build(int idx,int l,int r){
    seg[idx].dq.clear();
    for(int i=l;i<=r;i++) seg[idx].add((line){sb[i],-1LL*sb[i]*i});
    if(l==r) return;   
    int mid=(l+r)/2;
    build(idx*2,l,mid),build(idx*2+1,mid+1,r);
}
ll query(int idx,int l,int r,int ql,int qr,int x){
    if(r<ql or l>qr) return 0;
    if(ql<=l and r<=qr) return seg[idx].query(x);
    int mid=(l+r)/2;
    return max(query(idx*2,l,mid,ql,qr,x),query(idx*2+1,mid+1,r,ql,qr,x));
}
void rec(int l,int r){
    if(l==r){
        MXTO(ans,1LL*a[l]*b[l]);
        return;
    }
    int mid=(l+r)/2;
    int ma=INF,mb=INF;
    sa[mid+1]=sb[mid+1]=INF;
    for(int i=mid;i>=l;i--){
        sa[i]=min(sa[i+1],a[i]),sb[i]=min(sb[i+1],b[i]);
    }
    int p=mid;
    for(int i=mid+1;i<=r;i++){
        MNTO(ma,a[i]),MNTO(mb,b[i]);
        while(p>=l and (sa[p]>=ma and sb[p]>=mb)) --p;
        MXTO(ans,1LL*(i-p)*ma*mb);
    }
    ma=INF,mb=INF;
    //min a on right
    //sa[l]>pa[r] sb[l]<pb[r]
    //forms a left bound, forms a right bound
    //left bound decreases, right bound decreases 
    //pain
    int x=mid,y=mid;
    build(1,l,mid);
    for(int i=mid+1;i<=r;i++){
        MNTO(ma,a[i]),MNTO(mb,b[i]);
        while(x>=l and sa[x]>ma) --x;
        while(y>=l and sb[y]>mb) --y;
        if(x+1<=y) MXTO(ans,1LL*query(1,l,mid,x+1,y,i+1)*ma);
    }
    rec(l,mid),rec(mid+1,r);
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    REP(i,n){
        cin>>a[i]>>b[i];
    }
    rec(0,n-1);
    reverse(a,a+n),reverse(b,b+n);
    rec(0,n-1);
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 266 ms 471536 KB Output is correct
2 Correct 264 ms 471596 KB Output is correct
3 Correct 264 ms 471632 KB Output is correct
4 Correct 259 ms 471496 KB Output is correct
5 Correct 263 ms 471616 KB Output is correct
6 Correct 262 ms 471496 KB Output is correct
7 Correct 267 ms 471528 KB Output is correct
8 Correct 270 ms 471488 KB Output is correct
9 Correct 261 ms 471528 KB Output is correct
10 Correct 265 ms 471520 KB Output is correct
11 Correct 272 ms 471560 KB Output is correct
12 Correct 260 ms 471592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 471536 KB Output is correct
2 Correct 264 ms 471596 KB Output is correct
3 Correct 264 ms 471632 KB Output is correct
4 Correct 259 ms 471496 KB Output is correct
5 Correct 263 ms 471616 KB Output is correct
6 Correct 262 ms 471496 KB Output is correct
7 Correct 267 ms 471528 KB Output is correct
8 Correct 270 ms 471488 KB Output is correct
9 Correct 261 ms 471528 KB Output is correct
10 Correct 265 ms 471520 KB Output is correct
11 Correct 272 ms 471560 KB Output is correct
12 Correct 260 ms 471592 KB Output is correct
13 Correct 719 ms 474840 KB Output is correct
14 Correct 740 ms 474876 KB Output is correct
15 Correct 657 ms 474704 KB Output is correct
16 Correct 699 ms 474692 KB Output is correct
17 Correct 766 ms 474740 KB Output is correct
18 Correct 846 ms 475100 KB Output is correct
19 Correct 809 ms 474860 KB Output is correct
20 Correct 825 ms 474920 KB Output is correct
21 Correct 703 ms 474692 KB Output is correct
22 Correct 809 ms 474688 KB Output is correct
23 Incorrect 296 ms 471868 KB Output isn't correct
24 Halted 0 ms 0 KB -