#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 1e9+5;
struct segtree {
vector<int> values;
int size;
void init(int n) {
size = 1;
while(size < n) size *= 2;
values.resize(2*size);
}
void build(vector<int> &a, int x = 0, int lx = 0, int rx = -1) {
if (rx == -1) rx = size;
if (lx == rx) {
if (lx < a.size())
values[x] = a[lx];
return;
}
int m = lx + ((rx - lx) >> 1);
build(a, 2 * x, lx, m);
build(a, 2 * x+1, m+1, rx);
values[x] = max(values[2*x], values[2*x+1]);
}
int get(int l, int r, int x, int lx, int rx) {
if (l <= lx && rx <= r) {
return values[x];
}
int m = lx + ((rx - lx) >> 1), ret = 0;
if (l <= m) {
ret = max(ret, get(l, r, 2*x, lx, m));
}
if (m < r) {
ret = max(ret, get(l, r, 2*x+1, m+1, rx));
}
return ret;
}
int get(int l, int r) {
return get(l, r, 0, 0, size);
}
};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
}
segtree st;
st.init(n);
st.build(x);
int ans = 0;
int l = 0;
int maxx = -INF;
for (int i = 0; i < n; ++i) {
if (y[i] < maxx) {
l++;
int r = i;
while (l < r) {
int m = l + ((r - l) >> 1);
int d = st.get(m, i);
if (y[i] < d) {
l = m+1;
} else {
r = m;
}
}
maxx = st.get(l, i);
}
maxx = max(maxx, x[i]);
ans = max(ans, i - l + 1);
}
cout << ans << "\n";
return 0;
}
Compilation message
tem.cpp: In member function 'void segtree::build(std::vector<int>&, int, int, int)':
tem.cpp:19:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if (lx < a.size())
| ~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
112 ms |
10932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
223 ms |
24708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
279 ms |
30104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
321 ms |
33796 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
383 ms |
31476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
166 ms |
20120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
186 ms |
19500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
316 ms |
29248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
279 ms |
28468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |