#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, Q;
vector<array<int, 2> > v;
struct segment {
const int dim = 1 << 19;
struct node {
int val, prop;
node(int a = -1, int b = -1) {
val = a;
prop = b;
}
};
vector<node> s = vector<node>(2 * dim);
void prop(int pos) {
if (pos >= dim || s[pos].prop == -1) return;
s[2 * pos].val = s[pos].prop;
s[2 * pos].prop = s[pos].prop;
s[2 * pos + 1].val = s[pos].prop;
s[2 * pos + 1].prop = s[pos].prop;
}
void upd(int pos, int l, int r, int a, int b, int k) {
prop(pos);
if (r < a || l > b) return;
if (a <= l && r <= b) {
s[pos].val = k;
s[pos].prop = k;
return;
}
int m = (l + r) / 2;
upd(2 * pos, l, m, a, b, k);
upd(2 * pos + 1, m + 1, r, a, b, k);
s[pos].val = max(s[2 * pos].val, s[2 * pos + 1].val);
s[pos].prop = -1;
}
int query(int pos, int l, int r, int a, int b) {
prop(pos);
if (r < a || l > b) return -1;
if (a <= l && r <= b) return s[pos].val;
int m = (l + r) / 2;
return max(query(2 * pos, l, m, a, b), query(2 * pos + 1, m + 1, r, a, b));
}
void upd(int a, int b, int k) {
upd(1, 0, dim - 1, a, b, k);
}
int query(int a, int b) {
return query(1, 0, dim - 1, a, b);
}
} seg;
vector<int> r(200010);
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
vector<int> x;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
v.pb({a, b});
x.pb(a);
x.pb(b);
}
sort(x.begin(), x.end());
x.resize(unique(x.begin(), x.end()) - x.begin());
for (int i = 0; i < N; i++) {
v[i][0] = lower_bound(x.begin(), x.end(), v[i][0]) - x.begin();
v[i][1] = lower_bound(x.begin(), x.end(), v[i][1]) - x.begin();
}
for (int i = 0; i < N; i++) {
r[i] = seg.query(v[i][0], v[i][1]);
seg.upd(v[i][0], v[i][1], i);
if (i) r[i] = max(r[i], r[i - 1]);
}
cin >> Q;
for (int i = 0; i < Q; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
int tot = 0;
int pos = b;
while (pos >= a) {
tot++;
pos = r[pos];
}
cout << tot << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
28212 KB |
Output is correct |
2 |
Correct |
459 ms |
28064 KB |
Output is correct |
3 |
Correct |
517 ms |
28092 KB |
Output is correct |
4 |
Correct |
449 ms |
28208 KB |
Output is correct |
5 |
Correct |
489 ms |
28628 KB |
Output is correct |
6 |
Correct |
132 ms |
27684 KB |
Output is correct |
7 |
Correct |
139 ms |
27900 KB |
Output is correct |
8 |
Correct |
120 ms |
27892 KB |
Output is correct |
9 |
Correct |
118 ms |
28056 KB |
Output is correct |
10 |
Correct |
145 ms |
27772 KB |
Output is correct |
11 |
Correct |
290 ms |
27872 KB |
Output is correct |
12 |
Correct |
248 ms |
27240 KB |
Output is correct |
13 |
Correct |
255 ms |
27180 KB |
Output is correct |
14 |
Correct |
279 ms |
27884 KB |
Output is correct |
15 |
Correct |
243 ms |
27624 KB |
Output is correct |
16 |
Correct |
9 ms |
18212 KB |
Output is correct |
17 |
Correct |
149 ms |
28364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18756 KB |
Output is correct |
2 |
Correct |
25 ms |
18756 KB |
Output is correct |
3 |
Correct |
28 ms |
18752 KB |
Output is correct |
4 |
Correct |
28 ms |
18720 KB |
Output is correct |
5 |
Correct |
25 ms |
18644 KB |
Output is correct |
6 |
Correct |
28 ms |
18716 KB |
Output is correct |
7 |
Correct |
26 ms |
18644 KB |
Output is correct |
8 |
Correct |
20 ms |
18756 KB |
Output is correct |
9 |
Correct |
18 ms |
18772 KB |
Output is correct |
10 |
Correct |
15 ms |
18724 KB |
Output is correct |
11 |
Correct |
13 ms |
18644 KB |
Output is correct |
12 |
Correct |
13 ms |
18680 KB |
Output is correct |
13 |
Correct |
13 ms |
18644 KB |
Output is correct |
14 |
Correct |
14 ms |
18644 KB |
Output is correct |
15 |
Correct |
13 ms |
18644 KB |
Output is correct |
16 |
Correct |
10 ms |
18260 KB |
Output is correct |
17 |
Correct |
53 ms |
18740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18756 KB |
Output is correct |
2 |
Correct |
25 ms |
18756 KB |
Output is correct |
3 |
Correct |
28 ms |
18752 KB |
Output is correct |
4 |
Correct |
28 ms |
18720 KB |
Output is correct |
5 |
Correct |
25 ms |
18644 KB |
Output is correct |
6 |
Correct |
28 ms |
18716 KB |
Output is correct |
7 |
Correct |
26 ms |
18644 KB |
Output is correct |
8 |
Correct |
20 ms |
18756 KB |
Output is correct |
9 |
Correct |
18 ms |
18772 KB |
Output is correct |
10 |
Correct |
15 ms |
18724 KB |
Output is correct |
11 |
Correct |
13 ms |
18644 KB |
Output is correct |
12 |
Correct |
13 ms |
18680 KB |
Output is correct |
13 |
Correct |
13 ms |
18644 KB |
Output is correct |
14 |
Correct |
14 ms |
18644 KB |
Output is correct |
15 |
Correct |
13 ms |
18644 KB |
Output is correct |
16 |
Correct |
10 ms |
18260 KB |
Output is correct |
17 |
Correct |
53 ms |
18740 KB |
Output is correct |
18 |
Correct |
462 ms |
21372 KB |
Output is correct |
19 |
Correct |
420 ms |
21052 KB |
Output is correct |
20 |
Correct |
497 ms |
21456 KB |
Output is correct |
21 |
Correct |
410 ms |
21340 KB |
Output is correct |
22 |
Correct |
467 ms |
21296 KB |
Output is correct |
23 |
Correct |
579 ms |
21356 KB |
Output is correct |
24 |
Correct |
430 ms |
21316 KB |
Output is correct |
25 |
Correct |
334 ms |
21540 KB |
Output is correct |
26 |
Correct |
275 ms |
21272 KB |
Output is correct |
27 |
Correct |
196 ms |
21020 KB |
Output is correct |
28 |
Correct |
52 ms |
20656 KB |
Output is correct |
29 |
Correct |
54 ms |
20776 KB |
Output is correct |
30 |
Correct |
54 ms |
20812 KB |
Output is correct |
31 |
Correct |
55 ms |
20684 KB |
Output is correct |
32 |
Correct |
58 ms |
20700 KB |
Output is correct |
33 |
Correct |
9 ms |
18256 KB |
Output is correct |
34 |
Execution timed out |
1088 ms |
20388 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
28648 KB |
Output is correct |
2 |
Correct |
443 ms |
28440 KB |
Output is correct |
3 |
Correct |
391 ms |
27760 KB |
Output is correct |
4 |
Correct |
407 ms |
27672 KB |
Output is correct |
5 |
Correct |
408 ms |
28056 KB |
Output is correct |
6 |
Correct |
112 ms |
27816 KB |
Output is correct |
7 |
Correct |
119 ms |
27684 KB |
Output is correct |
8 |
Correct |
123 ms |
27716 KB |
Output is correct |
9 |
Correct |
120 ms |
27628 KB |
Output is correct |
10 |
Correct |
126 ms |
28324 KB |
Output is correct |
11 |
Correct |
249 ms |
27324 KB |
Output is correct |
12 |
Correct |
252 ms |
28172 KB |
Output is correct |
13 |
Correct |
206 ms |
27152 KB |
Output is correct |
14 |
Correct |
241 ms |
27476 KB |
Output is correct |
15 |
Correct |
247 ms |
28056 KB |
Output is correct |
16 |
Correct |
9 ms |
18260 KB |
Output is correct |
17 |
Correct |
144 ms |
27964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
28212 KB |
Output is correct |
2 |
Correct |
459 ms |
28064 KB |
Output is correct |
3 |
Correct |
517 ms |
28092 KB |
Output is correct |
4 |
Correct |
449 ms |
28208 KB |
Output is correct |
5 |
Correct |
489 ms |
28628 KB |
Output is correct |
6 |
Correct |
132 ms |
27684 KB |
Output is correct |
7 |
Correct |
139 ms |
27900 KB |
Output is correct |
8 |
Correct |
120 ms |
27892 KB |
Output is correct |
9 |
Correct |
118 ms |
28056 KB |
Output is correct |
10 |
Correct |
145 ms |
27772 KB |
Output is correct |
11 |
Correct |
290 ms |
27872 KB |
Output is correct |
12 |
Correct |
248 ms |
27240 KB |
Output is correct |
13 |
Correct |
255 ms |
27180 KB |
Output is correct |
14 |
Correct |
279 ms |
27884 KB |
Output is correct |
15 |
Correct |
243 ms |
27624 KB |
Output is correct |
16 |
Correct |
9 ms |
18212 KB |
Output is correct |
17 |
Correct |
149 ms |
28364 KB |
Output is correct |
18 |
Correct |
29 ms |
18756 KB |
Output is correct |
19 |
Correct |
25 ms |
18756 KB |
Output is correct |
20 |
Correct |
28 ms |
18752 KB |
Output is correct |
21 |
Correct |
28 ms |
18720 KB |
Output is correct |
22 |
Correct |
25 ms |
18644 KB |
Output is correct |
23 |
Correct |
28 ms |
18716 KB |
Output is correct |
24 |
Correct |
26 ms |
18644 KB |
Output is correct |
25 |
Correct |
20 ms |
18756 KB |
Output is correct |
26 |
Correct |
18 ms |
18772 KB |
Output is correct |
27 |
Correct |
15 ms |
18724 KB |
Output is correct |
28 |
Correct |
13 ms |
18644 KB |
Output is correct |
29 |
Correct |
13 ms |
18680 KB |
Output is correct |
30 |
Correct |
13 ms |
18644 KB |
Output is correct |
31 |
Correct |
14 ms |
18644 KB |
Output is correct |
32 |
Correct |
13 ms |
18644 KB |
Output is correct |
33 |
Correct |
10 ms |
18260 KB |
Output is correct |
34 |
Correct |
53 ms |
18740 KB |
Output is correct |
35 |
Correct |
462 ms |
21372 KB |
Output is correct |
36 |
Correct |
420 ms |
21052 KB |
Output is correct |
37 |
Correct |
497 ms |
21456 KB |
Output is correct |
38 |
Correct |
410 ms |
21340 KB |
Output is correct |
39 |
Correct |
467 ms |
21296 KB |
Output is correct |
40 |
Correct |
579 ms |
21356 KB |
Output is correct |
41 |
Correct |
430 ms |
21316 KB |
Output is correct |
42 |
Correct |
334 ms |
21540 KB |
Output is correct |
43 |
Correct |
275 ms |
21272 KB |
Output is correct |
44 |
Correct |
196 ms |
21020 KB |
Output is correct |
45 |
Correct |
52 ms |
20656 KB |
Output is correct |
46 |
Correct |
54 ms |
20776 KB |
Output is correct |
47 |
Correct |
54 ms |
20812 KB |
Output is correct |
48 |
Correct |
55 ms |
20684 KB |
Output is correct |
49 |
Correct |
58 ms |
20700 KB |
Output is correct |
50 |
Correct |
9 ms |
18256 KB |
Output is correct |
51 |
Execution timed out |
1088 ms |
20388 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |