#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B>
string to_string(pair<A, B>);
string to_string(string S) {
return '"' + S + '"';
}
string to_string(const char* c) {
return to_string(string(c));
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template<size_t T>
string to_string(bitset<T> bs) {
return bs.to_string();
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < int(v.size()); ++i) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(v[i]);
}
return res + "}";
}
template<typename T>
string to_string(T v) {
string res = "{";
for (auto e : v) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(e);
}
return res + "}";
}
template<typename A, typename B>
string to_string(pair<A, B> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename H, typename... T>
void debug_out(H head, T... tail) {
cerr << " " << to_string(head);
debug_out(tail...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(37)
#endif
struct node {
int mn = -1;
int tag = -1;
void modify(int x) {
tag = max(tag, x);
mn = max(mn, x);
}
};
node unite(node x, node y) {
return node{min(x.mn, y.mn), -1};
}
const int inf = int(1e9);
#define def int mid = (l + r) >> 1, rv = v + ((mid - l + 1) * 2)
struct SegTree {
vector<node> tree;
int n;
void push(int v, int l, int r) {
def;
if (tree[v].tag != -1) {
tree[v + 1].modify(tree[v].tag);
tree[rv].modify(tree[v].tag);
tree[v].tag = -1;
}
}
void modify(int v, int l, int r, int ll, int rr, int x) {
if (l >= ll && rr >= r) {
tree[v].modify(x);
return;
}
def;
push(v, l, r);
if (mid >= ll) {
modify(v + 1, l, mid, ll, rr, x);
}
if (mid < rr) {
modify(rv, mid + 1, r, ll, rr, x);
}
tree[v] = unite(tree[v + 1], tree[rv]);
}
int get(int v, int l, int r, int ll, int rr) {
if (l >= ll && rr >= r) {
return tree[v].mn;
}
def;
push(v, l, r);
int res = inf;
if (mid >= ll) {
res = min(res, get(v + 1, l, mid, ll, rr));
}
if (mid < rr) {
res = min(res, get(rv, mid + 1, r, ll, rr));
}
return res;
}
SegTree(int _n) : n(_n) {
tree.resize(n * 2);
}
void modify(int ll, int rr, int x) {
modify(0, 0, n - 1, ll, rr, x);
}
int get(int ll, int rr) {
return get(0, 0, n - 1, ll, rr);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, M, Q;
cin >> N >> M >> Q;
vector<int> L(M), R(M);
for (int i = 0; i < M; ++i) {
cin >> L[i] >> R[i];
--L[i], --R[i];
}
vector<int> S(Q), E(Q);
for (int i = 0; i < Q; ++i) {
cin >> S[i] >> E[i];
--S[i], --E[i];
}
debug(L, R, S, E);
vector<vector<int>> lefts(N);
for (int i = 0; i < M; ++i) {
lefts[R[i]].push_back(L[i]);
}
vector<vector<int>> qs(N);
for (int i = 0; i < Q; ++i) {
qs[E[i]].push_back(i);
}
debug(lefts, qs);
vector<bool> ans(Q);
SegTree st(N);
for (int i = 0; i < N; ++i) {
for (auto l : lefts[i]) {
st.modify(l, i, l);
}
for (auto q : qs[i]) {
ans[q] = st.get(S[q], i) >= S[q];
}
}
for (int i = 0; i < Q; ++i) {
cout << (ans[i] ? "YES" : "NO") << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
472 KB |
Output is correct |
22 |
Correct |
144 ms |
9296 KB |
Output is correct |
23 |
Correct |
151 ms |
9576 KB |
Output is correct |
24 |
Correct |
183 ms |
11040 KB |
Output is correct |
25 |
Correct |
297 ms |
16356 KB |
Output is correct |
26 |
Correct |
155 ms |
9520 KB |
Output is correct |
27 |
Correct |
301 ms |
16472 KB |
Output is correct |
28 |
Correct |
305 ms |
16332 KB |
Output is correct |
29 |
Correct |
131 ms |
9028 KB |
Output is correct |
30 |
Correct |
97 ms |
9556 KB |
Output is correct |
31 |
Correct |
111 ms |
10320 KB |
Output is correct |
32 |
Correct |
276 ms |
16464 KB |
Output is correct |
33 |
Correct |
95 ms |
9808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
664 KB |
Output is correct |
8 |
Correct |
96 ms |
9508 KB |
Output is correct |
9 |
Correct |
125 ms |
10404 KB |
Output is correct |
10 |
Correct |
239 ms |
16476 KB |
Output is correct |
11 |
Correct |
107 ms |
9696 KB |
Output is correct |
12 |
Correct |
89 ms |
13396 KB |
Output is correct |
13 |
Correct |
90 ms |
13392 KB |
Output is correct |
14 |
Correct |
65 ms |
13452 KB |
Output is correct |
15 |
Correct |
69 ms |
13264 KB |
Output is correct |
16 |
Correct |
65 ms |
13392 KB |
Output is correct |
17 |
Correct |
91 ms |
13244 KB |
Output is correct |
18 |
Correct |
620 ms |
65884 KB |
Output is correct |
19 |
Correct |
635 ms |
65876 KB |
Output is correct |
20 |
Correct |
490 ms |
66648 KB |
Output is correct |
21 |
Correct |
539 ms |
65808 KB |
Output is correct |
22 |
Correct |
619 ms |
64820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
472 KB |
Output is correct |
22 |
Correct |
86 ms |
4436 KB |
Output is correct |
23 |
Correct |
87 ms |
4432 KB |
Output is correct |
24 |
Correct |
127 ms |
12128 KB |
Output is correct |
25 |
Correct |
128 ms |
12132 KB |
Output is correct |
26 |
Correct |
105 ms |
13420 KB |
Output is correct |
27 |
Correct |
107 ms |
13360 KB |
Output is correct |
28 |
Correct |
90 ms |
11368 KB |
Output is correct |
29 |
Correct |
104 ms |
12704 KB |
Output is correct |
30 |
Correct |
119 ms |
12020 KB |
Output is correct |
31 |
Correct |
131 ms |
12156 KB |
Output is correct |
32 |
Correct |
135 ms |
12628 KB |
Output is correct |
33 |
Correct |
98 ms |
12940 KB |
Output is correct |
34 |
Correct |
126 ms |
11480 KB |
Output is correct |
35 |
Correct |
130 ms |
11900 KB |
Output is correct |
36 |
Correct |
108 ms |
12632 KB |
Output is correct |
37 |
Correct |
95 ms |
13468 KB |
Output is correct |
38 |
Correct |
98 ms |
13480 KB |
Output is correct |
39 |
Correct |
81 ms |
13656 KB |
Output is correct |
40 |
Correct |
72 ms |
13136 KB |
Output is correct |
41 |
Correct |
85 ms |
13580 KB |
Output is correct |
42 |
Correct |
80 ms |
13248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
472 KB |
Output is correct |
22 |
Correct |
144 ms |
9296 KB |
Output is correct |
23 |
Correct |
151 ms |
9576 KB |
Output is correct |
24 |
Correct |
183 ms |
11040 KB |
Output is correct |
25 |
Correct |
297 ms |
16356 KB |
Output is correct |
26 |
Correct |
155 ms |
9520 KB |
Output is correct |
27 |
Correct |
301 ms |
16472 KB |
Output is correct |
28 |
Correct |
305 ms |
16332 KB |
Output is correct |
29 |
Correct |
131 ms |
9028 KB |
Output is correct |
30 |
Correct |
97 ms |
9556 KB |
Output is correct |
31 |
Correct |
111 ms |
10320 KB |
Output is correct |
32 |
Correct |
276 ms |
16464 KB |
Output is correct |
33 |
Correct |
95 ms |
9808 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
664 KB |
Output is correct |
41 |
Correct |
96 ms |
9508 KB |
Output is correct |
42 |
Correct |
125 ms |
10404 KB |
Output is correct |
43 |
Correct |
239 ms |
16476 KB |
Output is correct |
44 |
Correct |
107 ms |
9696 KB |
Output is correct |
45 |
Correct |
89 ms |
13396 KB |
Output is correct |
46 |
Correct |
90 ms |
13392 KB |
Output is correct |
47 |
Correct |
65 ms |
13452 KB |
Output is correct |
48 |
Correct |
69 ms |
13264 KB |
Output is correct |
49 |
Correct |
65 ms |
13392 KB |
Output is correct |
50 |
Correct |
91 ms |
13244 KB |
Output is correct |
51 |
Correct |
620 ms |
65884 KB |
Output is correct |
52 |
Correct |
635 ms |
65876 KB |
Output is correct |
53 |
Correct |
490 ms |
66648 KB |
Output is correct |
54 |
Correct |
539 ms |
65808 KB |
Output is correct |
55 |
Correct |
619 ms |
64820 KB |
Output is correct |
56 |
Correct |
86 ms |
4436 KB |
Output is correct |
57 |
Correct |
87 ms |
4432 KB |
Output is correct |
58 |
Correct |
127 ms |
12128 KB |
Output is correct |
59 |
Correct |
128 ms |
12132 KB |
Output is correct |
60 |
Correct |
105 ms |
13420 KB |
Output is correct |
61 |
Correct |
107 ms |
13360 KB |
Output is correct |
62 |
Correct |
90 ms |
11368 KB |
Output is correct |
63 |
Correct |
104 ms |
12704 KB |
Output is correct |
64 |
Correct |
119 ms |
12020 KB |
Output is correct |
65 |
Correct |
131 ms |
12156 KB |
Output is correct |
66 |
Correct |
135 ms |
12628 KB |
Output is correct |
67 |
Correct |
98 ms |
12940 KB |
Output is correct |
68 |
Correct |
126 ms |
11480 KB |
Output is correct |
69 |
Correct |
130 ms |
11900 KB |
Output is correct |
70 |
Correct |
108 ms |
12632 KB |
Output is correct |
71 |
Correct |
95 ms |
13468 KB |
Output is correct |
72 |
Correct |
98 ms |
13480 KB |
Output is correct |
73 |
Correct |
81 ms |
13656 KB |
Output is correct |
74 |
Correct |
72 ms |
13136 KB |
Output is correct |
75 |
Correct |
85 ms |
13580 KB |
Output is correct |
76 |
Correct |
80 ms |
13248 KB |
Output is correct |
77 |
Correct |
785 ms |
59132 KB |
Output is correct |
78 |
Correct |
831 ms |
59148 KB |
Output is correct |
79 |
Correct |
655 ms |
65324 KB |
Output is correct |
80 |
Correct |
652 ms |
65540 KB |
Output is correct |
81 |
Correct |
623 ms |
63504 KB |
Output is correct |
82 |
Correct |
638 ms |
64520 KB |
Output is correct |
83 |
Correct |
778 ms |
59148 KB |
Output is correct |
84 |
Correct |
783 ms |
59164 KB |
Output is correct |
85 |
Correct |
611 ms |
61008 KB |
Output is correct |
86 |
Correct |
605 ms |
56840 KB |
Output is correct |
87 |
Correct |
621 ms |
57624 KB |
Output is correct |
88 |
Correct |
554 ms |
63688 KB |
Output is correct |