#include <bits/stdc++.h>
using namespace std;
const int maxn = 2E5+8;
int n, q, L[maxn], R[maxn];
struct segtree {
int size = 1;
vector<int> seg;
void init(int n) {
while (size < n) size *= 2;
seg.assign(2 * size + 5, 0);
}
void update(int pos, int val, int l, int r, int id) {
if (l == r) {
seg[id] = val;
return;
}
int mid = (l + r) >> 1;
update(pos, val, l, mid, id * 2);
update(pos, val, mid + 1, r, id * 2 + 1);
seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
int query(int ql, int qr, int l, int r, int id) {
if (ql <= l && r <= qr) return seg[id];
if (qr < l || r < ql) return 0;
int mid = (l + r) >> 1;
return max(query(ql, qr, l, mid, id * 2), query(ql, qr, mid + 1, r, id * 2 + 1));
}
} st;
int32_t main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> L[i] >> R[i];
vector<pair<int, int>> A;
for (int i = 1; i <= n; i++) A.emplace_back(L[i], R[i]);
st.init(n + 1);
sort(A.begin(), A.end());
cin >> q;
while (q--) {
int x;
cin >> x;
if (x == 1) {
int r = 1, pt = 0, ans = 0;
while (r < n) {
while (pt < n && A[pt].first <= r) {
st.update(A[pt].first, A[pt].second, 1, n, 1);
pt++;
}
int oldr = r;
r = st.query(1, r, 1, n, 1);
if (oldr == r) {
cout << "-1\n";
goto bye;
}
ans++;
}
cout << ans << "\n";
bye:{}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |