#include<bits/stdc++.h>
using namespace std;
struct segTree{
vector<int> v, upd;
int sz;
void init(int n){
sz = 1;
while(sz < n) sz *= 2;
v.assign(2 * sz, 1e9);
upd.assign(2 * sz, 1e9);
}
void set(int l, int r, int val, int x, int lx, int rx){
if(lx >= l && rx <= r){
v[x] = min(val, v[x]);
upd[x] = min(val, upd[x]);
return;
}else if(lx >= r || rx <= l) return;
int m = (lx + rx) / 2;
set(l, r, val, 2 * x + 1, lx, m);
set(l, r, val, 2 * x + 2, m, rx);
v[x] = min(max(v[2 * x + 1], v[2 * x + 2]), upd[x]);
}
void set(int l, int r, int val){
set(l, r, val, 0, 0, sz);
}
int compare(int a, int b){
if(a == 2e9) return b;
else if(b == 2e9) return a;
else return max(a, b);
}
int calc(int l, int r, int x, int lx, int rx){
if(lx >= l && rx <= r) return v[x];
else if(lx >= r || rx <= l) return 2e9;
int m = (lx + rx) / 2;
int c1 = calc(l, r, 2 * x + 1, lx, m);
int c2 = calc(l, r, 2 * x + 2, m, rx);
// cout << "x "<< x << " lx "<< lx << " rx "<< rx << " v[x] "<< v[x] << " upd[x] "<< upd[x] << " c1 "<< c1 << " c2 "<< c2 << "\n";
return min(compare(c1, c2), upd[x]);
}
int calc(int l, int r){
return calc(l, r, 0, 0, sz);
}
};
void solve(){
int n, m, q; cin >> n >> m >> q;
vector<vector<int>> startCurtain(n);
for(int i = 0; i < m; i++){
int l, r; cin >> l >> r; l--; r--;
startCurtain[l].push_back(r);
}
vector<vector<int>> startQuery(n);
vector<pair<int, int>> queries(q);
for(int i = 0; i < q; i++){
int l, r; cin >> l >> r; l--; r--;
queries[i] = {l, r};
startQuery[l].push_back(i);
}
segTree st; st.init(n);
vector<bool> ans(q);
for(int i = n - 1; i >= 0; i--){
for(int r : startCurtain[i]){
// cout << "add "<< i << " "<< r << " " << endl;
st.set(i, r + 1, r);
}
for(int j : startQuery[i]){
int l = queries[j].first;
int r = queries[j].second;
// cout << "l "<< l << " r "<< r << " calc "<< st.calc(l, r + 1) << "\n";
if(st.calc(l, r + 1) <= r) ans[j] = true;
else ans[j] = false;
}
}
for(bool b : ans){
if(b) cout << "YES\n";
else cout << "NO\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// int tt; cin >> tt;
int tt = 1;
while(tt--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 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 |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 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 |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 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 |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
167 ms |
13704 KB |
Output is correct |
23 |
Correct |
156 ms |
14180 KB |
Output is correct |
24 |
Correct |
210 ms |
15436 KB |
Output is correct |
25 |
Correct |
271 ms |
21080 KB |
Output is correct |
26 |
Correct |
161 ms |
13752 KB |
Output is correct |
27 |
Correct |
301 ms |
21136 KB |
Output is correct |
28 |
Correct |
291 ms |
20880 KB |
Output is correct |
29 |
Correct |
176 ms |
13644 KB |
Output is correct |
30 |
Correct |
110 ms |
11608 KB |
Output is correct |
31 |
Correct |
123 ms |
12480 KB |
Output is correct |
32 |
Correct |
230 ms |
19036 KB |
Output is correct |
33 |
Correct |
105 ms |
11716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
576 KB |
Output is correct |
8 |
Correct |
112 ms |
11588 KB |
Output is correct |
9 |
Correct |
125 ms |
12484 KB |
Output is correct |
10 |
Correct |
228 ms |
19140 KB |
Output is correct |
11 |
Correct |
109 ms |
11696 KB |
Output is correct |
12 |
Correct |
94 ms |
12572 KB |
Output is correct |
13 |
Correct |
85 ms |
12492 KB |
Output is correct |
14 |
Correct |
66 ms |
12512 KB |
Output is correct |
15 |
Correct |
69 ms |
12500 KB |
Output is correct |
16 |
Correct |
70 ms |
12500 KB |
Output is correct |
17 |
Correct |
64 ms |
12512 KB |
Output is correct |
18 |
Correct |
572 ms |
59612 KB |
Output is correct |
19 |
Correct |
548 ms |
59732 KB |
Output is correct |
20 |
Correct |
455 ms |
60492 KB |
Output is correct |
21 |
Correct |
427 ms |
60264 KB |
Output is correct |
22 |
Correct |
453 ms |
60420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 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 |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
76 ms |
5716 KB |
Output is correct |
23 |
Correct |
71 ms |
5716 KB |
Output is correct |
24 |
Correct |
127 ms |
14164 KB |
Output is correct |
25 |
Correct |
114 ms |
14176 KB |
Output is correct |
26 |
Correct |
85 ms |
15700 KB |
Output is correct |
27 |
Correct |
91 ms |
15700 KB |
Output is correct |
28 |
Correct |
68 ms |
13400 KB |
Output is correct |
29 |
Correct |
84 ms |
15276 KB |
Output is correct |
30 |
Correct |
110 ms |
14164 KB |
Output is correct |
31 |
Correct |
100 ms |
14152 KB |
Output is correct |
32 |
Correct |
93 ms |
14528 KB |
Output is correct |
33 |
Correct |
110 ms |
14684 KB |
Output is correct |
34 |
Correct |
103 ms |
13792 KB |
Output is correct |
35 |
Correct |
91 ms |
13396 KB |
Output is correct |
36 |
Correct |
88 ms |
13908 KB |
Output is correct |
37 |
Correct |
80 ms |
12492 KB |
Output is correct |
38 |
Correct |
86 ms |
12492 KB |
Output is correct |
39 |
Correct |
67 ms |
12500 KB |
Output is correct |
40 |
Correct |
64 ms |
12604 KB |
Output is correct |
41 |
Correct |
64 ms |
12676 KB |
Output is correct |
42 |
Correct |
63 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 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 |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
167 ms |
13704 KB |
Output is correct |
23 |
Correct |
156 ms |
14180 KB |
Output is correct |
24 |
Correct |
210 ms |
15436 KB |
Output is correct |
25 |
Correct |
271 ms |
21080 KB |
Output is correct |
26 |
Correct |
161 ms |
13752 KB |
Output is correct |
27 |
Correct |
301 ms |
21136 KB |
Output is correct |
28 |
Correct |
291 ms |
20880 KB |
Output is correct |
29 |
Correct |
176 ms |
13644 KB |
Output is correct |
30 |
Correct |
110 ms |
11608 KB |
Output is correct |
31 |
Correct |
123 ms |
12480 KB |
Output is correct |
32 |
Correct |
230 ms |
19036 KB |
Output is correct |
33 |
Correct |
105 ms |
11716 KB |
Output is correct |
34 |
Correct |
1 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 |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
576 KB |
Output is correct |
41 |
Correct |
112 ms |
11588 KB |
Output is correct |
42 |
Correct |
125 ms |
12484 KB |
Output is correct |
43 |
Correct |
228 ms |
19140 KB |
Output is correct |
44 |
Correct |
109 ms |
11696 KB |
Output is correct |
45 |
Correct |
94 ms |
12572 KB |
Output is correct |
46 |
Correct |
85 ms |
12492 KB |
Output is correct |
47 |
Correct |
66 ms |
12512 KB |
Output is correct |
48 |
Correct |
69 ms |
12500 KB |
Output is correct |
49 |
Correct |
70 ms |
12500 KB |
Output is correct |
50 |
Correct |
64 ms |
12512 KB |
Output is correct |
51 |
Correct |
572 ms |
59612 KB |
Output is correct |
52 |
Correct |
548 ms |
59732 KB |
Output is correct |
53 |
Correct |
455 ms |
60492 KB |
Output is correct |
54 |
Correct |
427 ms |
60264 KB |
Output is correct |
55 |
Correct |
453 ms |
60420 KB |
Output is correct |
56 |
Correct |
76 ms |
5716 KB |
Output is correct |
57 |
Correct |
71 ms |
5716 KB |
Output is correct |
58 |
Correct |
127 ms |
14164 KB |
Output is correct |
59 |
Correct |
114 ms |
14176 KB |
Output is correct |
60 |
Correct |
85 ms |
15700 KB |
Output is correct |
61 |
Correct |
91 ms |
15700 KB |
Output is correct |
62 |
Correct |
68 ms |
13400 KB |
Output is correct |
63 |
Correct |
84 ms |
15276 KB |
Output is correct |
64 |
Correct |
110 ms |
14164 KB |
Output is correct |
65 |
Correct |
100 ms |
14152 KB |
Output is correct |
66 |
Correct |
93 ms |
14528 KB |
Output is correct |
67 |
Correct |
110 ms |
14684 KB |
Output is correct |
68 |
Correct |
103 ms |
13792 KB |
Output is correct |
69 |
Correct |
91 ms |
13396 KB |
Output is correct |
70 |
Correct |
88 ms |
13908 KB |
Output is correct |
71 |
Correct |
80 ms |
12492 KB |
Output is correct |
72 |
Correct |
86 ms |
12492 KB |
Output is correct |
73 |
Correct |
67 ms |
12500 KB |
Output is correct |
74 |
Correct |
64 ms |
12604 KB |
Output is correct |
75 |
Correct |
64 ms |
12676 KB |
Output is correct |
76 |
Correct |
63 ms |
12632 KB |
Output is correct |
77 |
Correct |
792 ms |
69124 KB |
Output is correct |
78 |
Correct |
785 ms |
68936 KB |
Output is correct |
79 |
Correct |
705 ms |
76856 KB |
Output is correct |
80 |
Correct |
799 ms |
76856 KB |
Output is correct |
81 |
Correct |
679 ms |
74840 KB |
Output is correct |
82 |
Correct |
729 ms |
76120 KB |
Output is correct |
83 |
Correct |
784 ms |
68948 KB |
Output is correct |
84 |
Correct |
812 ms |
68888 KB |
Output is correct |
85 |
Correct |
769 ms |
69976 KB |
Output is correct |
86 |
Correct |
653 ms |
64012 KB |
Output is correct |
87 |
Correct |
628 ms |
63316 KB |
Output is correct |
88 |
Correct |
696 ms |
72788 KB |
Output is correct |