#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 5;
int n;
int a[maxN], b[maxN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("A.INP", "r", stdin);
//freopen("A.OUT", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
deque<int> dq;
int res = 1;
int ind = 0;
for (int i = 1; i <= n; i++) {
while (!dq.empty() && a[dq.front()] > b[i]) {
ind++;
if (dq.front() == ind) {
dq.pop_front();
}
}
while (!dq.empty() && a[dq.back()] < a[i]) {
dq.pop_back();
}
dq.push_back(i);
res = max(res, i - ind);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
8460 KB |
Output is correct |
2 |
Correct |
52 ms |
8724 KB |
Output is correct |
3 |
Correct |
57 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
12420 KB |
Output is correct |
2 |
Correct |
109 ms |
13140 KB |
Output is correct |
3 |
Correct |
121 ms |
14356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
15180 KB |
Output is correct |
2 |
Correct |
113 ms |
13432 KB |
Output is correct |
3 |
Correct |
147 ms |
17012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
17140 KB |
Output is correct |
2 |
Correct |
117 ms |
19540 KB |
Output is correct |
3 |
Correct |
180 ms |
30032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
16212 KB |
Output is correct |
2 |
Correct |
109 ms |
13908 KB |
Output is correct |
3 |
Correct |
113 ms |
13648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
10804 KB |
Output is correct |
2 |
Correct |
85 ms |
11344 KB |
Output is correct |
3 |
Correct |
85 ms |
10836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
10084 KB |
Output is correct |
2 |
Correct |
87 ms |
11748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
14960 KB |
Output is correct |
2 |
Correct |
164 ms |
19832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
14692 KB |
Output is correct |
2 |
Correct |
152 ms |
18256 KB |
Output is correct |