#ifndef LOCAL
#define FAST_IO
#endif
// ============
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, m, n) for (i32 i = (i32)(m); i < (i32)(n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)
using namespace std;
using u32 = unsigned int;
using u64 = unsigned long long;
using i32 = signed int;
using i64 = signed long long;
using f64 = double;
using f80 = long double;
template <typename T>
using Vec = vector<T>;
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
#ifdef INT128
using u128 = __uint128_t;
using i128 = __int128_t;
istream &operator>>(istream &is, i128 &x) {
i64 v;
is >> v;
x = v;
return is;
}
ostream &operator<<(ostream &os, i128 x) {
os << (i64)x;
return os;
}
istream &operator>>(istream &is, u128 &x) {
u64 v;
is >> v;
x = v;
return is;
}
ostream &operator<<(ostream &os, u128 x) {
os << (u64)x;
return os;
}
#endif
[[maybe_unused]] constexpr i32 INF = 1000000100;
[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;
struct SetUpIO {
SetUpIO() {
#ifdef FAST_IO
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
cout << fixed << setprecision(15);
}
} set_up_io;
// ============
#ifdef DEBUGF
#else
#define DBG(x) (void)0
#endif
// ============
#include <cassert>
#include <utility>
#include <vector>
template <typename MonoidFunc>
class LazySegmentTree {
public:
using Value = typename MonoidFunc::Value;
using Func = typename MonoidFunc::Func;
private:
int old_length;
int lg;
int length;
std::vector<Value> values;
std::vector<Func> funcs;
static int lg2(int n) {
int x = 1;
int l = 0;
while (x < n) {
x <<= 1;
++l;
}
return l;
}
void _apply(int idx, const Func &func) {
values[idx] = MonoidFunc::apply(func, values[idx]);
funcs[idx] = MonoidFunc::composite(func, funcs[idx]);
}
void push(int idx) {
_apply(idx << 1, funcs[idx]);
_apply(idx << 1 | 1, funcs[idx]);
funcs[idx] = MonoidFunc::func_id();
}
void recalc_values(int idx) {
values[idx] = MonoidFunc::op(values[idx << 1], values[idx << 1 | 1]);
}
public:
LazySegmentTree(int n) :
old_length(n),
lg(lg2(n)),
length(1 << lg),
values(length << 1, MonoidFunc::id()),
funcs(length << 1, MonoidFunc::func_id()) {
assert(n >= 0);
}
LazySegmentTree(const std::vector<Value> &v) :
old_length((int) v.size()),
lg(lg2(old_length)),
length(1 << lg),
values(length << 1, MonoidFunc::id()),
funcs(length << 1, MonoidFunc::func_id()) {
for (int i = 0; i < old_length; ++i) {
values[i + length] = v[i];
}
for (int i = length - 1; i > 0; --i) {
recalc_values(i);
}
}
template <typename F>
LazySegmentTree(int n, const F &f) :
old_length(n),
lg(lg2(n)),
length(1 << lg),
values(length << 1, MonoidFunc::id()),
funcs(length << 1, MonoidFunc::func_id()) {
for (int i = 0; i < old_length; ++i) {
values[i + length] = f(i);
}
for (int i = length - 1; i > 0; --i) {
recalc_values(i);
}
}
void update(int idx, Value val) {
assert(idx >= 0 && idx < old_length);
idx += length;
for (int i = lg; i > 0; --i) {
push(idx >> i);
}
values[idx] = std::move(val);
while (idx >>= 1) {
recalc_values(idx);
}
}
void apply(int l, int r, const Func &func) {
assert(l >= 0 && l <= r && r <= old_length);
if (l == r) {
return;
}
l += length;
r += length;
int _l = l;
int _r = r;
for (int i = lg; i > 0; --i) {
push(_l >> i);
push((_r - 1) >> i);
}
while (l < r) {
if (l & 1) {
_apply(l++, func);
}
if (r & 1) {
_apply(--r, func);
}
l >>= 1;
r >>= 1;
}
for (int i = 1; i <= lg; ++i) {
if ((_l >> i << i) != _l) {
recalc_values(_l >> i);
}
if ((_r >> i << i) != _r) {
recalc_values((_r - 1) >> i);
}
}
}
Value prod(int l, int r) {
assert(l >= 0 && l <= r && r <= old_length);
if (l == r) {
return MonoidFunc::id();
}
l += length;
r += length;
for (int i = lg; i > 0; --i) {
push(l >> i);
push((r - 1) >> i);
}
Value lp = MonoidFunc::id();
Value rp = MonoidFunc::id();
while (l < r) {
if (l & 1) {
lp = MonoidFunc::op(lp, values[l++]);
}
if (r & 1) {
rp = MonoidFunc::op(values[--r], rp);
}
l >>= 1;
r >>= 1;
}
return MonoidFunc::op(lp, rp);
}
Value all_prod() const {
return values[1];
}
};
// ============
struct Ops {
using Value = i32;
using Func = i32;
static Value id() {
return -1;
}
static Value op(Value x, Value y) {
return max(x, y);
}
static Func func_id() {
return INF;
}
static Func composite(Func f, Func g) {
return min(f, g);
}
static Value apply(Func f, Value x) {
return min(f, x);
}
};
int main() {
i32 n, m, q;
cin >> n >> m >> q;
Vec<i32> l(m), r(m);
REP(i, m) {
cin >> l[i] >> r[i];
--l[i];
}
Vec<i32> s(q), e(q);
REP(i, q) {
cin >> s[i] >> e[i];
--s[i];
}
Vec<Vec<i32>> rs(n), qs(n);
REP(i, m) {
rs[l[i]].push_back(r[i]);
}
REP(i, q) {
qs[s[i]].push_back(i);
}
LazySegmentTree<Ops> seg(n, [](i32) -> i32 {
return INF;
});
Vec<i32> ans(q, 0);
PER(i, n) {
for (i32 j : rs[i]) {
seg.apply(i, j, j);
}
for (i32 j : qs[i]) {
if (seg.prod(i, e[j]) <= e[j]) {
ans[j] = 1;
}
}
}
REP(i, q) {
if (ans[i]) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
134 ms |
15588 KB |
Output is correct |
23 |
Correct |
142 ms |
15956 KB |
Output is correct |
24 |
Correct |
161 ms |
18128 KB |
Output is correct |
25 |
Correct |
285 ms |
27216 KB |
Output is correct |
26 |
Correct |
143 ms |
15728 KB |
Output is correct |
27 |
Correct |
278 ms |
27012 KB |
Output is correct |
28 |
Correct |
282 ms |
26928 KB |
Output is correct |
29 |
Correct |
140 ms |
15480 KB |
Output is correct |
30 |
Correct |
125 ms |
13608 KB |
Output is correct |
31 |
Correct |
143 ms |
14712 KB |
Output is correct |
32 |
Correct |
258 ms |
24960 KB |
Output is correct |
33 |
Correct |
123 ms |
13888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
126 ms |
13620 KB |
Output is correct |
9 |
Correct |
138 ms |
14784 KB |
Output is correct |
10 |
Correct |
268 ms |
25080 KB |
Output is correct |
11 |
Correct |
125 ms |
13736 KB |
Output is correct |
12 |
Correct |
89 ms |
13512 KB |
Output is correct |
13 |
Correct |
98 ms |
13664 KB |
Output is correct |
14 |
Correct |
82 ms |
13868 KB |
Output is correct |
15 |
Correct |
81 ms |
13768 KB |
Output is correct |
16 |
Correct |
82 ms |
13844 KB |
Output is correct |
17 |
Correct |
85 ms |
13768 KB |
Output is correct |
18 |
Correct |
612 ms |
65524 KB |
Output is correct |
19 |
Correct |
574 ms |
65476 KB |
Output is correct |
20 |
Correct |
526 ms |
66296 KB |
Output is correct |
21 |
Correct |
503 ms |
66300 KB |
Output is correct |
22 |
Correct |
514 ms |
66056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
80 ms |
7004 KB |
Output is correct |
23 |
Correct |
74 ms |
6888 KB |
Output is correct |
24 |
Correct |
111 ms |
15324 KB |
Output is correct |
25 |
Correct |
107 ms |
15316 KB |
Output is correct |
26 |
Correct |
96 ms |
16840 KB |
Output is correct |
27 |
Correct |
120 ms |
16852 KB |
Output is correct |
28 |
Correct |
84 ms |
14316 KB |
Output is correct |
29 |
Correct |
103 ms |
16356 KB |
Output is correct |
30 |
Correct |
113 ms |
15332 KB |
Output is correct |
31 |
Correct |
106 ms |
15328 KB |
Output is correct |
32 |
Correct |
108 ms |
15680 KB |
Output is correct |
33 |
Correct |
94 ms |
16016 KB |
Output is correct |
34 |
Correct |
100 ms |
14928 KB |
Output is correct |
35 |
Correct |
106 ms |
14516 KB |
Output is correct |
36 |
Correct |
115 ms |
15076 KB |
Output is correct |
37 |
Correct |
93 ms |
13516 KB |
Output is correct |
38 |
Correct |
91 ms |
13668 KB |
Output is correct |
39 |
Correct |
84 ms |
13864 KB |
Output is correct |
40 |
Correct |
79 ms |
13768 KB |
Output is correct |
41 |
Correct |
94 ms |
13768 KB |
Output is correct |
42 |
Correct |
81 ms |
13764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
2 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
134 ms |
15588 KB |
Output is correct |
23 |
Correct |
142 ms |
15956 KB |
Output is correct |
24 |
Correct |
161 ms |
18128 KB |
Output is correct |
25 |
Correct |
285 ms |
27216 KB |
Output is correct |
26 |
Correct |
143 ms |
15728 KB |
Output is correct |
27 |
Correct |
278 ms |
27012 KB |
Output is correct |
28 |
Correct |
282 ms |
26928 KB |
Output is correct |
29 |
Correct |
140 ms |
15480 KB |
Output is correct |
30 |
Correct |
125 ms |
13608 KB |
Output is correct |
31 |
Correct |
143 ms |
14712 KB |
Output is correct |
32 |
Correct |
258 ms |
24960 KB |
Output is correct |
33 |
Correct |
123 ms |
13888 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
38 |
Correct |
2 ms |
600 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
126 ms |
13620 KB |
Output is correct |
42 |
Correct |
138 ms |
14784 KB |
Output is correct |
43 |
Correct |
268 ms |
25080 KB |
Output is correct |
44 |
Correct |
125 ms |
13736 KB |
Output is correct |
45 |
Correct |
89 ms |
13512 KB |
Output is correct |
46 |
Correct |
98 ms |
13664 KB |
Output is correct |
47 |
Correct |
82 ms |
13868 KB |
Output is correct |
48 |
Correct |
81 ms |
13768 KB |
Output is correct |
49 |
Correct |
82 ms |
13844 KB |
Output is correct |
50 |
Correct |
85 ms |
13768 KB |
Output is correct |
51 |
Correct |
612 ms |
65524 KB |
Output is correct |
52 |
Correct |
574 ms |
65476 KB |
Output is correct |
53 |
Correct |
526 ms |
66296 KB |
Output is correct |
54 |
Correct |
503 ms |
66300 KB |
Output is correct |
55 |
Correct |
514 ms |
66056 KB |
Output is correct |
56 |
Correct |
80 ms |
7004 KB |
Output is correct |
57 |
Correct |
74 ms |
6888 KB |
Output is correct |
58 |
Correct |
111 ms |
15324 KB |
Output is correct |
59 |
Correct |
107 ms |
15316 KB |
Output is correct |
60 |
Correct |
96 ms |
16840 KB |
Output is correct |
61 |
Correct |
120 ms |
16852 KB |
Output is correct |
62 |
Correct |
84 ms |
14316 KB |
Output is correct |
63 |
Correct |
103 ms |
16356 KB |
Output is correct |
64 |
Correct |
113 ms |
15332 KB |
Output is correct |
65 |
Correct |
106 ms |
15328 KB |
Output is correct |
66 |
Correct |
108 ms |
15680 KB |
Output is correct |
67 |
Correct |
94 ms |
16016 KB |
Output is correct |
68 |
Correct |
100 ms |
14928 KB |
Output is correct |
69 |
Correct |
106 ms |
14516 KB |
Output is correct |
70 |
Correct |
115 ms |
15076 KB |
Output is correct |
71 |
Correct |
93 ms |
13516 KB |
Output is correct |
72 |
Correct |
91 ms |
13668 KB |
Output is correct |
73 |
Correct |
84 ms |
13864 KB |
Output is correct |
74 |
Correct |
79 ms |
13768 KB |
Output is correct |
75 |
Correct |
94 ms |
13768 KB |
Output is correct |
76 |
Correct |
81 ms |
13764 KB |
Output is correct |
77 |
Correct |
725 ms |
74700 KB |
Output is correct |
78 |
Correct |
699 ms |
74576 KB |
Output is correct |
79 |
Correct |
670 ms |
82828 KB |
Output is correct |
80 |
Correct |
708 ms |
82768 KB |
Output is correct |
81 |
Correct |
669 ms |
80048 KB |
Output is correct |
82 |
Correct |
677 ms |
81844 KB |
Output is correct |
83 |
Correct |
695 ms |
74760 KB |
Output is correct |
84 |
Correct |
728 ms |
74948 KB |
Output is correct |
85 |
Correct |
673 ms |
75804 KB |
Output is correct |
86 |
Correct |
617 ms |
69828 KB |
Output is correct |
87 |
Correct |
600 ms |
68944 KB |
Output is correct |
88 |
Correct |
660 ms |
78496 KB |
Output is correct |