#include <bits/stdc++.h>
using namespace std;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair <int, int> arr[n + 1];
for (int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second;
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
set <pair <int, int>> cur;
cur.insert(arr[l]);
int cnt = 1;
for (int i = l + 1; i <= r; i++) {
auto x = cur.lower_bound({arr[i].second + 1, 0});
if (x == cur.begin()) {
cur.insert(arr[i]);
continue;
}
x--;
auto l = *x;
if (arr[i].first >= l.first && arr[i].first <= l.second) {
cur.clear(); cnt++;
} else if (arr[i].second >= l.first && arr[i].second <= l.second) {
cur.clear(); cnt++;
}
cur.insert(arr[i]);
}
cout << cnt << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
1924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
314 ms |
480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
314 ms |
480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
289 ms |
1988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
1924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |