// Super Idol的笑容
// 都没你的甜
// 八月正午的阳光
// 都没你耀眼
// 热爱105°C的你
// 滴滴清纯的蒸馏水
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct node{
int s,e,m;
int val=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void update(int i,int k){
if (s==e){
val=k;
}
else{
if (i<=m) l->update(i,k);
else r->update(i,k);
val=min(l->val,r->val);
}
}
int query(int i,int j){
if (s==i && e==j) return val;
else{
if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return min(l->query(i,m),r->query(m+1,j));
}
}
} *root2=new node(0,200005);
int n;
int arr[200005];
int brr[200005];
struct range{
int l,r,v;
};
vector<range> ar,br;
struct line{
int m=0,c=-1e12;
int get(int x){
return m*x+c;
}
};
struct lichao{
int s,e,m;
line val;
lichao *l,*r;
lichao (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new lichao(s,m);
r=new lichao(m+1,e);
}
}
void update(line k){
bool lo=val.get(s)<k.get(s);
bool mi=val.get(m)<k.get(m);
bool hi=val.get(e)<k.get(e);
if (mi) swap(val,k);
if (lo==hi || k.c==-1e18 || s==e) return;
if (lo!=mi) l->update(k);
else r->update(k);
}
void update(int i,int j,line k){
// if (s==0 && e==200005){
// rep(x,i,j+1) cout<<k.get(x)<<" "; cout<<endl;
// }
if (s==i && e==j) update(k);
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
}
}
int query(int i){
if (s==e) return val.get(i);
else if (i<=m) return max(val.get(i),l->query(i));
else return max(val.get(i),r->query(i));
}
} *root;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n;
rep(x,1,n+1) cin>>arr[x]>>brr[x];
rep(x,1,n+1) root2->update(x,brr[x]);
ll ans=0;
rep(zzz,0,2){
root=new lichao(0,200005);
reverse(arr+1,arr+n+1);
reverse(brr+1,brr+n+1);
ar.clear(),br.clear();
vector<int> idx={0};
rep(x,1,n+2){
while (arr[idx.back()]>arr[x]){
int temp=arr[idx.back()];
idx.pob();
ar.pub(range({idx.back()+1,x-1,temp}));
if (zzz) ans=max(ans,temp*(x-idx.back()-1)*root2->query(idx.back()+1,x-1));
}
idx.pub(x);
}
idx={0};
rep(x,1,n+2){
while (brr[idx.back()]>brr[x]){
int temp=brr[idx.back()];
idx.pob();
br.pub(range({idx.back()+1,x-1,temp}));
}
idx.pub(x);
}
sort(all(ar),[](range i,range j){
return i.r<j.r;
});
sort(all(br),[](range i,range j){
return i.r<j.r;
});
int pos=0;
for (auto [l,r,v]:ar){
while (pos!=sz(br) && br[pos].r<=r){
int l=br[pos].l,r=br[pos].r,v=br[pos].v;
//cout<<"adding: "<<l<<" "<<r<<" "<<v<<endl;
root->update(l,r,line({-v,(r+1)*v}));
root->update(0,l-1,line({0,(r-l+1)*v}));
pos++;
}
ans=max(ans,v*root->query(l));
}
}
cout<<ans<<endl;
}
Compilation message
histogram.cpp: In constructor 'node::node(long long int, long long int)':
histogram.cpp:46:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | s=_s,e=_e,m=s+e>>1;
| ~^~
histogram.cpp: In constructor 'lichao::lichao(long long int, long long int)':
histogram.cpp:98:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
98 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
75544 KB |
Output is correct |
2 |
Correct |
52 ms |
75596 KB |
Output is correct |
3 |
Correct |
70 ms |
75628 KB |
Output is correct |
4 |
Correct |
58 ms |
75508 KB |
Output is correct |
5 |
Correct |
53 ms |
75536 KB |
Output is correct |
6 |
Correct |
55 ms |
75516 KB |
Output is correct |
7 |
Correct |
52 ms |
75524 KB |
Output is correct |
8 |
Correct |
53 ms |
75528 KB |
Output is correct |
9 |
Correct |
53 ms |
75592 KB |
Output is correct |
10 |
Correct |
58 ms |
75592 KB |
Output is correct |
11 |
Correct |
54 ms |
75420 KB |
Output is correct |
12 |
Correct |
57 ms |
75540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
75544 KB |
Output is correct |
2 |
Correct |
52 ms |
75596 KB |
Output is correct |
3 |
Correct |
70 ms |
75628 KB |
Output is correct |
4 |
Correct |
58 ms |
75508 KB |
Output is correct |
5 |
Correct |
53 ms |
75536 KB |
Output is correct |
6 |
Correct |
55 ms |
75516 KB |
Output is correct |
7 |
Correct |
52 ms |
75524 KB |
Output is correct |
8 |
Correct |
53 ms |
75528 KB |
Output is correct |
9 |
Correct |
53 ms |
75592 KB |
Output is correct |
10 |
Correct |
58 ms |
75592 KB |
Output is correct |
11 |
Correct |
54 ms |
75420 KB |
Output is correct |
12 |
Correct |
57 ms |
75540 KB |
Output is correct |
13 |
Correct |
342 ms |
90564 KB |
Output is correct |
14 |
Correct |
319 ms |
91536 KB |
Output is correct |
15 |
Correct |
307 ms |
89372 KB |
Output is correct |
16 |
Correct |
273 ms |
89644 KB |
Output is correct |
17 |
Correct |
317 ms |
90972 KB |
Output is correct |
18 |
Correct |
308 ms |
91020 KB |
Output is correct |
19 |
Correct |
310 ms |
91128 KB |
Output is correct |
20 |
Correct |
314 ms |
90956 KB |
Output is correct |
21 |
Correct |
282 ms |
89680 KB |
Output is correct |
22 |
Correct |
325 ms |
91080 KB |
Output is correct |
23 |
Correct |
79 ms |
76992 KB |
Output is correct |
24 |
Correct |
338 ms |
92672 KB |
Output is correct |