2369. Interval
Decision monotonic
First we deal with the interval, if the interval is the interval contains other, then we do not consider it
After processing, all sections showing \ (l, r \) is incremented, the set interval selected must be a contiguous range
Then our decision-making monotony of divide and conquer to solve the monotony: \ (J \) with \ (i \) is incremented incremented
For that interval is included, the case will not produce the above-mentioned contribution (to take a certain period interval containing it better)
In another case, the contribution is generated between the included between the sections containing it, is the election period of the longest interval operator include its contribution to
const int N=1e6+10;
int n,m;
struct Node{
int l,r;
} A[N];
struct CMP{
bool operator () (const Node a,const Node b){
if(a.l!=b.l) return a.l<b.l;
return a.r>b.r;
}
};
inline void chk(ll &x,ll y){ ((x<y)&&(x=y)); }
inline void chk(int &x,int y){ ((x<y)&&(x=y)); }
ll ans;
void Solve(int l,int r,int L,int R){
if(l>r) return;
int mid=(l+r)>>1;
ll ma=-1e18,id=0;
rep(i,max(L,mid+1),R) {
ll t=1ll*(A[mid].r-A[i].l)*(A[i].r-A[mid].l);
((t>ma)&&(ma=t,id=i));
}
chk(ans,ma);
Solve(l,mid-1,L,id);
Solve(mid+1,r,id,R);
}
int s[N];
void Add(int p,int x) {
p++;
while(p) chk(s[p],x),p-=p&-p;
}
int Que(int p) {
p++;
int res=0;
while(p<N) chk(res,s[p]),p+=p&-p;
return res;
}
int main(){
n=rd();
rep(i,1,n) A[i].l=rd(),A[i].r=rd();
sort(A+1,A+n+1,CMP());
int ma=0;
rep(i,1,n) {
if(A[i].r<=A[i].l) continue;
if(ma<A[i].r) {
A[++m]=A[i];
ma=A[i].r;
Add(A[i].r,A[i].r-A[i].l);
} else chk(ans,1ll*Que(A[i].r)*(A[i].r-A[i].l));//被包含时,选一段最长的包含它的区间,即lj<=li
}
n=m;
Solve(1,n,1,n);
printf("%lld\n",ans);
}