#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=1e6+5;
vector<int> lo(N),hi(N);
struct SegmentTree{
vector<int> m;
int n;
void init(int nn)
{
n=nn;
m.resize(2*n);
for(int i=n;i<2*n;i++)
m[i]=lo[i-n];
for(int j=n-1;j>0;j--)
m[j]=max(m[2*j],m[2*j+1]);
}
void set(int i,int k)
{
i+=n;
m[i]=k;
i>>=1;
for(;i;i>>=1)
m[i]=max(m[2*i],m[2*i+1]);
}
int get(int l,int r)
{
int ma=INT_MIN;
for(l+=n,r+=n;l<=r;l>>=1,r>>=1)
{
if(l%2==1)
{
ma=max(ma,m[l]);
l++;
}
if(r%2==0)
{
ma=max(ma,m[r]);
r--;
}
}
return ma;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
SegmentTree m;
int n;
cin >> n;
for(int i=0;i<n;i++)
cin >> lo[i] >> hi[i];
m.init(n);
int l=0;
int maxx=INT_MIN;
int res=0;
for(int i=0;i<n;i++)
{
if(hi[i]<maxx)
{
l++;
int r=i;
while(l<r)
{
int mid=(l+r)/2;
int d=m.get(mid,i);
//printf("%i-%i [%i][%i]=%i\n",l,r,mid,i,d);
if(hi[i]<d)
{
l=mid+1;
}
else
{
r=mid;
}
}
maxx=m.get(l,i);
}
maxx=max(maxx,lo[i]);
res=max(res,i-l+1);
//printf("%i-%i %i %i\n",l,i,maxx,res);
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8332 KB |
Output is correct |
2 |
Correct |
8 ms |
8332 KB |
Output is correct |
3 |
Correct |
8 ms |
8408 KB |
Output is correct |
4 |
Correct |
8 ms |
8428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8552 KB |
Output is correct |
2 |
Correct |
12 ms |
8572 KB |
Output is correct |
3 |
Correct |
11 ms |
8576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
12080 KB |
Output is correct |
2 |
Correct |
102 ms |
12460 KB |
Output is correct |
3 |
Correct |
103 ms |
13060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
14212 KB |
Output is correct |
2 |
Correct |
200 ms |
15624 KB |
Output is correct |
3 |
Correct |
529 ms |
15624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
15624 KB |
Output is correct |
2 |
Correct |
218 ms |
15712 KB |
Output is correct |
3 |
Correct |
604 ms |
15760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
292 ms |
16352 KB |
Output is correct |
2 |
Correct |
216 ms |
16352 KB |
Output is correct |
3 |
Correct |
797 ms |
17268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
17268 KB |
Output is correct |
2 |
Correct |
378 ms |
17268 KB |
Output is correct |
3 |
Correct |
206 ms |
17268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
17268 KB |
Output is correct |
2 |
Correct |
141 ms |
17268 KB |
Output is correct |
3 |
Correct |
147 ms |
17268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
167 ms |
17268 KB |
Output is correct |
2 |
Correct |
152 ms |
17268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
225 ms |
17268 KB |
Output is correct |
2 |
Correct |
734 ms |
17268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
17268 KB |
Output is correct |
2 |
Correct |
675 ms |
17268 KB |
Output is correct |