#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
struct LazySegmentTree {
vector <int> lzy, f;
int n;
LazySegmentTree(int _n) {
n = _n;
lzy.resize(n * 4 + 5, 0);
f.resize(n * 4 + 5, 0);
}
int merge(int x, int y) { return max(x, y); }
void push(int x, int l, int r) {
if (!lzy[x]) return;
int val = lzy[x];
f[x << 1] = max(f[x << 1], val);
lzy[x << 1] = val;
f[x << 1 | 1] = max(f[x << 1 | 1], val);
lzy[x << 1 | 1] = val;
lzy[x] = 0;
return;
}
void upd(int x, int l, int r, int u, int v, int val) {
if (l > v || r < u) return;
if (u <= l && r <= v) {
f[x] = max(f[x], val);
lzy[x] = val;
return;
}
int m = (l + r) / 2;
push(x, l, r);
upd(x << 1, l, m, u, v, val);
upd(x << 1 | 1, m + 1, r, u, v, val);
f[x] = merge(f[x << 1], f[x << 1 | 1]);
}
void upd(int l, int r, int val) { upd(1, 1, n, l, r, val); }
int qry(int x, int l, int r, int u, int v) {
if (l > v || r < u) return 0;
if (u <= l && r <= v) return f[x];
int m = (l + r) / 2;
push(x, l, r);
int ql = qry(x << 1, l, m, u, v);
int qr = qry(x << 1 | 1, m + 1, r, u, v);
return merge(ql, qr);
}
int qry(int l, int r) { return qry(1, 1, n, l, r); }
};
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#ifdef JASPER
freopen("in1", "r", stdin);
#endif
vector <int> vals;
int n, q;
cin >> n;
vector <pair <int, int>> segs(n);
for (int i = 0; i < n; ++i) {
cin >> segs[i].first >> segs[i].second;
vals.push_back(segs[i].first);
vals.push_back(segs[i].second);
}
sort(vals.begin(), vals.end());
vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
for (int i = 0; i < n; ++i) {
segs[i].first = (int) (lower_bound(vals.begin(), vals.end(), segs[i].first) - vals.begin());
segs[i].second = (int) (lower_bound(vals.begin(), vals.end(), segs[i].second) - vals.begin());
}
cin >> q;
for (int _q = 1; _q <= q; ++_q) {
int l, r;
cin >> l >> r;
LazySegmentTree st((int) vals.size());
int res = 0;
int cnt = 0;
for (int i = l; i <= r; ++i) {
auto [x, y] = segs[i];
if (st.qry(x, y) == cnt) {
res++;
cnt++;
}
st.upd(x, y, cnt);
}
++res;
cout << res << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
17356 KB |
Output is correct |
2 |
Correct |
242 ms |
18728 KB |
Output is correct |
3 |
Incorrect |
249 ms |
18876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
1060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
1060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1041 ms |
18480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
17356 KB |
Output is correct |
2 |
Correct |
242 ms |
18728 KB |
Output is correct |
3 |
Incorrect |
249 ms |
18876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |