#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;
const int maxN = 1e6 + 1;
int a[maxN], b[maxN], n;
deque<int> q;
void ReadInput()
{
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
}
void Solve()
{
b[n + 1] = -1e9 - 1;
int res = 0, j = 0;
for (int i = 1; i <= n; i++)
{
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);
}
res = max(res, j - i + 1);
}
cout << res;
}
#define task ""
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
int T = 1;
//cin >> T;
while (T--)
{
ReadInput();
Solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
9812 KB |
Output is correct |
2 |
Correct |
54 ms |
10340 KB |
Output is correct |
3 |
Correct |
65 ms |
10612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
17488 KB |
Output is correct |
2 |
Correct |
117 ms |
18532 KB |
Output is correct |
3 |
Correct |
112 ms |
19792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
22848 KB |
Output is correct |
2 |
Correct |
114 ms |
19060 KB |
Output is correct |
3 |
Correct |
143 ms |
25328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
25904 KB |
Output is correct |
2 |
Correct |
151 ms |
19616 KB |
Output is correct |
3 |
Correct |
189 ms |
30140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
24144 KB |
Output is correct |
2 |
Correct |
112 ms |
18000 KB |
Output is correct |
3 |
Correct |
114 ms |
19252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
12644 KB |
Output is correct |
2 |
Correct |
87 ms |
12772 KB |
Output is correct |
3 |
Correct |
87 ms |
13028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
12112 KB |
Output is correct |
2 |
Correct |
86 ms |
13140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
22240 KB |
Output is correct |
2 |
Correct |
169 ms |
29664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
21584 KB |
Output is correct |
2 |
Correct |
158 ms |
27220 KB |
Output is correct |