This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int a[N],b[N],stv[2][25][N],st[25][N],lg[N],n;
void buildv(){
for (int i=1;i<=n;i++) stv[0][0][i]=a[i];
for (int i=1;i<=n;i++) stv[1][0][i]=b[i];
for (int i=1;i<25;i++){
for (int j=1;j+(1<<i)<=n+1;j++){
stv[0][i][j]=min(stv[0][i-1][j],stv[0][i-1][j+(1<<(i-1))]);
stv[1][i][j]=min(stv[1][i-1][j],stv[1][i-1][j+(1<<(i-1))]);
}
}
}
int queryv(int l,int r){
int i=lg[r-l+1];
return min(stv[0][i][l],stv[0][i][r-(1<<i)+1])*min(stv[1][i][l],stv[1][i][r-(1<<i)+1])*(r-l+1);
}
/*void build(){
for (int i=0;i<25;i++){
for (int j=1;j+(1<<i)<=n+1;j++){
st[i][j]=queryv(j,j+(1<<i)-1);
}
}
return;
}
int query(int l,int r){
int i=lg[r-l+1];
return max(st[i][l],st[i][r-(1<<i)+1]);
}*/
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
for (int i=2;i<N;i++) lg[i]=lg[i/2]+1;
for (int i=0;i<2;i++){
for (int j=0;j<25;j++){
for (int k=0;k<N;k++) stv[i][j][k]=INT_MAX;
}
}
cin>>n;
for (int i=1;i<=n;i++) cin>>a[i]>>b[i];
buildv();
//build();
int ans=0;
for (int i=1;i<=n;i++){
for (int j=i;j<=n;j++) ans=max(ans,queryv(i,j));
}cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |