This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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] = max(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;
struct passport {
int l, r, id;
bool operator < (const passport& o) const {
return id < o.id;
}
};
int32_t main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> L[i] >> R[i];
vector<passport> A;
for (int i = 1; i <= n; i++) A.push_back((passport) {L[i], R[i], 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].id <= r) {
st.update(A[pt].l, A[pt].r, 1, n, 1);
pt++;
}
int oldr = r;
r = st.query(1, r, 1, n, 1);
if (r <= oldr) {
cout << "-1\n";
goto bye;
}
ans++;
}
cout << ans << "\n";
bye:{}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |