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>
using namespace std;
#define ll long long
#define pb push_back
int ma;
const int N=2*1e6+5;
int m[N];
int n;
int i,k,l0,l,r,r0,nn;
int maxx=INT_MIN;
int res=0;
int hi,lo,mid,d,a;
struct SegmentTree{
void set()
{
a+=n;
m[a]=k;
a>>=1;
for(;a;a>>=1)
m[a]=max(m[2*a],m[2*a+1]);
}
int get()
{
ma=INT_MIN;
for(l0+=n,r0+=n;l0<=r0;l0>>=1,r0>>=1)
{
if(l0%2==1)
{
ma=max(ma,m[l0]);
l0++;
}
if(r0%2==0)
{
ma=max(ma,m[r0]);
r0--;
}
}
return ma;
}
};
int main()
{
SegmentTree m;
//n=1e6;
//scanf("%i",&n);
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cin >> n;
assert(n<N);
for(i=0;i<n;i++)
{
//scanf("%i %i",&lo,&hi);
cin >> lo >> hi;
a=i;
k=lo;
m.set();
if(hi<maxx)
{
l++;
r=i;
while(l<r)
{
mid=(l+r)/2;
l0=mid;
r0=i;
d=m.get();
//printf("%i-%i [%i][%i]=%i\n",l,r,mid,i,d);
if(hi<d)
{
l=mid+1;
}
else
{
r=mid;
}
}
l0=l;
r0=i;
maxx=m.get();
}
maxx=max(maxx,lo);
res=max(res,i-l+1);
}
//printf("%i\n",res);
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |