/*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[3*maxn];
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 |
233 ms |
404248 KB |
Output is correct |
2 |
Correct |
226 ms |
404292 KB |
Output is correct |
3 |
Correct |
233 ms |
404168 KB |
Output is correct |
4 |
Correct |
252 ms |
404192 KB |
Output is correct |
5 |
Correct |
226 ms |
404256 KB |
Output is correct |
6 |
Correct |
239 ms |
404292 KB |
Output is correct |
7 |
Correct |
232 ms |
404164 KB |
Output is correct |
8 |
Correct |
226 ms |
404224 KB |
Output is correct |
9 |
Correct |
231 ms |
404284 KB |
Output is correct |
10 |
Correct |
246 ms |
404196 KB |
Output is correct |
11 |
Correct |
226 ms |
404204 KB |
Output is correct |
12 |
Correct |
253 ms |
404296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
404248 KB |
Output is correct |
2 |
Correct |
226 ms |
404292 KB |
Output is correct |
3 |
Correct |
233 ms |
404168 KB |
Output is correct |
4 |
Correct |
252 ms |
404192 KB |
Output is correct |
5 |
Correct |
226 ms |
404256 KB |
Output is correct |
6 |
Correct |
239 ms |
404292 KB |
Output is correct |
7 |
Correct |
232 ms |
404164 KB |
Output is correct |
8 |
Correct |
226 ms |
404224 KB |
Output is correct |
9 |
Correct |
231 ms |
404284 KB |
Output is correct |
10 |
Correct |
246 ms |
404196 KB |
Output is correct |
11 |
Correct |
226 ms |
404204 KB |
Output is correct |
12 |
Correct |
253 ms |
404296 KB |
Output is correct |
13 |
Correct |
700 ms |
409228 KB |
Output is correct |
14 |
Correct |
695 ms |
409932 KB |
Output is correct |
15 |
Correct |
610 ms |
408816 KB |
Output is correct |
16 |
Correct |
695 ms |
408836 KB |
Output is correct |
17 |
Correct |
732 ms |
409936 KB |
Output is correct |
18 |
Correct |
861 ms |
410000 KB |
Output is correct |
19 |
Correct |
792 ms |
409912 KB |
Output is correct |
20 |
Correct |
788 ms |
410008 KB |
Output is correct |
21 |
Correct |
661 ms |
408832 KB |
Output is correct |
22 |
Correct |
769 ms |
409940 KB |
Output is correct |
23 |
Incorrect |
255 ms |
404548 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |