#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 10;
const int inf = 0x3f3f3f3f;
int a[maxN], b[maxN];
signed main(){
int n;
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i] >> b[i];
}
deque <int> Q;
int i = 1, j = 0;
b[n + 1] = -inf;
int ans = 1;
while (i <= n){
while (!Q.empty() && Q.front() < i) Q.pop_front();
if (j < i){
j = i;
Q.push_back(i);
}
while (j <= n && a[Q.front()] <= b[j + 1]){
++j;
while (!Q.empty() && a[Q.back()] <= a[j]) Q.pop_back();
Q.push_back(j);
}
ans = max(ans, j - i + 1);
++i;
}
cout << ans;
}
//
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2396 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
4 ms |
2500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
6600 KB |
Output is correct |
2 |
Correct |
151 ms |
6748 KB |
Output is correct |
3 |
Correct |
170 ms |
6736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
332 ms |
7004 KB |
Output is correct |
2 |
Correct |
354 ms |
7256 KB |
Output is correct |
3 |
Correct |
366 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
433 ms |
7260 KB |
Output is correct |
2 |
Correct |
373 ms |
7516 KB |
Output is correct |
3 |
Correct |
458 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
520 ms |
7772 KB |
Output is correct |
2 |
Correct |
394 ms |
7828 KB |
Output is correct |
3 |
Correct |
574 ms |
9560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
466 ms |
7732 KB |
Output is correct |
2 |
Correct |
346 ms |
8016 KB |
Output is correct |
3 |
Correct |
370 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
231 ms |
7516 KB |
Output is correct |
2 |
Correct |
237 ms |
7508 KB |
Output is correct |
3 |
Correct |
239 ms |
7280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
229 ms |
7204 KB |
Output is correct |
2 |
Correct |
248 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
428 ms |
7248 KB |
Output is correct |
2 |
Correct |
567 ms |
9308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
405 ms |
7256 KB |
Output is correct |
2 |
Correct |
505 ms |
8604 KB |
Output is correct |