#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define int long long
struct query{
int l, r, ind;
string ans;
};
const int N = 5e5+3;
pair<int, int> lr[N];
int st[4*N], lz[4*N];
query qs[N];
void push(int v){
int lc = 2*v+1;
int rc = 2*v+2;
st[lc]=max(st[lc], lz[v]);
st[rc]=max(st[rc], lz[v]);
lz[lc]=max(lz[lc], lz[v]);
lz[rc]=max(lz[rc], lz[v]);
st[v]=min(st[lc], st[rc]);
}
void Update(int v, int l, int r, int L, int R, int val){
if(l>r || l>R || r<L)return;
if(l>=L && r<=R){
st[v]=max(st[v], val);
lz[v]=max(lz[v], val);
return;
}
push(v);
int mid = l+r>>1;
Update(2*v+1, l, mid, L, R, val);
Update(2*v+2, mid+1, r, L, R, val);
st[v]=min(st[2*v+1], st[2*v+2]);
}
int Get(int v, int l, int r, int L, int R){
if(l>r || l>R || r<L)return 1e9;
if(l>=L && r<=R)return st[v];
push(v);
int mid = l+r>>1;
return min(Get(2*v+1, l, mid, L, R), Get(2*v+2, mid+1, r, L, R));
}
bool cmp1(query A, query B){
return A.r<B.r;
}
bool cmp2(query A, query B){
return A.ind < B.ind;
}
void solve(){
int n, m, q;
cin >> n >> m >> q;
for(int i=0; i< m; i++){
cin >> lr[i].S >> lr[i].F;
}
sort(lr, lr+m);
for(int i=0; i< m; i++){
swap(lr[i].F, lr[i].S);
}
for(int i=0; i< q; i++){
cin >> qs[i].l >> qs[i].r;
qs[i].ind=i;
}
sort(qs, qs+q, cmp1);
int p=0;
for(int i=0; i< q; i++){
while(p<m && lr[p].S<=qs[i].r){
Update(0, 1, n, lr[p].F, lr[p].S, lr[p].F);
p++;
}
if(Get(0, 1, n, qs[i].l, qs[i].r)>=qs[i].l)qs[i].ans="YES";
else qs[i].ans="NO";
}
sort(qs, qs+q, cmp2);
for(int i=0; i< q; i++){
cout << qs[i].ans << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
Compilation message
curtains.cpp: In function 'void Update(long long int, long long int, long long int, long long int, long long int, long long int)':
curtains.cpp:42:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid = l+r>>1;
| ~^~
curtains.cpp: In function 'long long int Get(long long int, long long int, long long int, long long int, long long int)':
curtains.cpp:52:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int mid = l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
31324 KB |
Output is correct |
2 |
Correct |
7 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31348 KB |
Output is correct |
4 |
Correct |
7 ms |
31320 KB |
Output is correct |
5 |
Correct |
8 ms |
31324 KB |
Output is correct |
6 |
Correct |
8 ms |
31340 KB |
Output is correct |
7 |
Correct |
6 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31364 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31404 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
31324 KB |
Output is correct |
2 |
Correct |
7 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31348 KB |
Output is correct |
4 |
Correct |
7 ms |
31320 KB |
Output is correct |
5 |
Correct |
8 ms |
31324 KB |
Output is correct |
6 |
Correct |
8 ms |
31340 KB |
Output is correct |
7 |
Correct |
6 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31364 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31404 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
9 ms |
31324 KB |
Output is correct |
14 |
Correct |
9 ms |
31448 KB |
Output is correct |
15 |
Correct |
9 ms |
31324 KB |
Output is correct |
16 |
Correct |
9 ms |
31320 KB |
Output is correct |
17 |
Correct |
8 ms |
31576 KB |
Output is correct |
18 |
Correct |
9 ms |
31336 KB |
Output is correct |
19 |
Correct |
9 ms |
31324 KB |
Output is correct |
20 |
Correct |
8 ms |
31324 KB |
Output is correct |
21 |
Correct |
10 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
31324 KB |
Output is correct |
2 |
Correct |
7 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31348 KB |
Output is correct |
4 |
Correct |
7 ms |
31320 KB |
Output is correct |
5 |
Correct |
8 ms |
31324 KB |
Output is correct |
6 |
Correct |
8 ms |
31340 KB |
Output is correct |
7 |
Correct |
6 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31364 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31404 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
9 ms |
31324 KB |
Output is correct |
14 |
Correct |
9 ms |
31448 KB |
Output is correct |
15 |
Correct |
9 ms |
31324 KB |
Output is correct |
16 |
Correct |
9 ms |
31320 KB |
Output is correct |
17 |
Correct |
8 ms |
31576 KB |
Output is correct |
18 |
Correct |
9 ms |
31336 KB |
Output is correct |
19 |
Correct |
9 ms |
31324 KB |
Output is correct |
20 |
Correct |
8 ms |
31324 KB |
Output is correct |
21 |
Correct |
10 ms |
31324 KB |
Output is correct |
22 |
Correct |
511 ms |
37324 KB |
Output is correct |
23 |
Correct |
518 ms |
37868 KB |
Output is correct |
24 |
Correct |
561 ms |
40528 KB |
Output is correct |
25 |
Correct |
720 ms |
48908 KB |
Output is correct |
26 |
Correct |
520 ms |
37448 KB |
Output is correct |
27 |
Correct |
713 ms |
48756 KB |
Output is correct |
28 |
Correct |
719 ms |
48908 KB |
Output is correct |
29 |
Correct |
505 ms |
37372 KB |
Output is correct |
30 |
Correct |
465 ms |
36756 KB |
Output is correct |
31 |
Correct |
467 ms |
36944 KB |
Output is correct |
32 |
Correct |
659 ms |
47784 KB |
Output is correct |
33 |
Correct |
455 ms |
36452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
7 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
9 ms |
31324 KB |
Output is correct |
6 |
Correct |
8 ms |
31324 KB |
Output is correct |
7 |
Correct |
8 ms |
31488 KB |
Output is correct |
8 |
Correct |
463 ms |
36440 KB |
Output is correct |
9 |
Correct |
476 ms |
36804 KB |
Output is correct |
10 |
Correct |
657 ms |
47700 KB |
Output is correct |
11 |
Correct |
456 ms |
36672 KB |
Output is correct |
12 |
Correct |
166 ms |
38484 KB |
Output is correct |
13 |
Correct |
160 ms |
38232 KB |
Output is correct |
14 |
Correct |
140 ms |
38224 KB |
Output is correct |
15 |
Correct |
144 ms |
38180 KB |
Output is correct |
16 |
Correct |
140 ms |
38096 KB |
Output is correct |
17 |
Correct |
142 ms |
38204 KB |
Output is correct |
18 |
Correct |
897 ms |
65716 KB |
Output is correct |
19 |
Correct |
902 ms |
66000 KB |
Output is correct |
20 |
Correct |
751 ms |
65364 KB |
Output is correct |
21 |
Correct |
755 ms |
65556 KB |
Output is correct |
22 |
Correct |
750 ms |
65552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
31324 KB |
Output is correct |
2 |
Correct |
7 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31348 KB |
Output is correct |
4 |
Correct |
7 ms |
31320 KB |
Output is correct |
5 |
Correct |
8 ms |
31324 KB |
Output is correct |
6 |
Correct |
8 ms |
31340 KB |
Output is correct |
7 |
Correct |
6 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31364 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31404 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
9 ms |
31324 KB |
Output is correct |
14 |
Correct |
9 ms |
31448 KB |
Output is correct |
15 |
Correct |
9 ms |
31324 KB |
Output is correct |
16 |
Correct |
9 ms |
31320 KB |
Output is correct |
17 |
Correct |
8 ms |
31576 KB |
Output is correct |
18 |
Correct |
9 ms |
31336 KB |
Output is correct |
19 |
Correct |
9 ms |
31324 KB |
Output is correct |
20 |
Correct |
8 ms |
31324 KB |
Output is correct |
21 |
Correct |
10 ms |
31324 KB |
Output is correct |
22 |
Correct |
162 ms |
35920 KB |
Output is correct |
23 |
Correct |
155 ms |
35984 KB |
Output is correct |
24 |
Correct |
182 ms |
38484 KB |
Output is correct |
25 |
Correct |
187 ms |
38552 KB |
Output is correct |
26 |
Correct |
158 ms |
38744 KB |
Output is correct |
27 |
Correct |
160 ms |
38736 KB |
Output is correct |
28 |
Correct |
141 ms |
35820 KB |
Output is correct |
29 |
Correct |
160 ms |
38480 KB |
Output is correct |
30 |
Correct |
184 ms |
38664 KB |
Output is correct |
31 |
Correct |
180 ms |
38620 KB |
Output is correct |
32 |
Correct |
172 ms |
38484 KB |
Output is correct |
33 |
Correct |
161 ms |
38712 KB |
Output is correct |
34 |
Correct |
177 ms |
38484 KB |
Output is correct |
35 |
Correct |
173 ms |
38484 KB |
Output is correct |
36 |
Correct |
172 ms |
38488 KB |
Output is correct |
37 |
Correct |
158 ms |
38240 KB |
Output is correct |
38 |
Correct |
166 ms |
38480 KB |
Output is correct |
39 |
Correct |
139 ms |
38188 KB |
Output is correct |
40 |
Correct |
141 ms |
38228 KB |
Output is correct |
41 |
Correct |
138 ms |
38164 KB |
Output is correct |
42 |
Correct |
142 ms |
38228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
31324 KB |
Output is correct |
2 |
Correct |
7 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31348 KB |
Output is correct |
4 |
Correct |
7 ms |
31320 KB |
Output is correct |
5 |
Correct |
8 ms |
31324 KB |
Output is correct |
6 |
Correct |
8 ms |
31340 KB |
Output is correct |
7 |
Correct |
6 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31364 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31404 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
9 ms |
31324 KB |
Output is correct |
14 |
Correct |
9 ms |
31448 KB |
Output is correct |
15 |
Correct |
9 ms |
31324 KB |
Output is correct |
16 |
Correct |
9 ms |
31320 KB |
Output is correct |
17 |
Correct |
8 ms |
31576 KB |
Output is correct |
18 |
Correct |
9 ms |
31336 KB |
Output is correct |
19 |
Correct |
9 ms |
31324 KB |
Output is correct |
20 |
Correct |
8 ms |
31324 KB |
Output is correct |
21 |
Correct |
10 ms |
31324 KB |
Output is correct |
22 |
Correct |
511 ms |
37324 KB |
Output is correct |
23 |
Correct |
518 ms |
37868 KB |
Output is correct |
24 |
Correct |
561 ms |
40528 KB |
Output is correct |
25 |
Correct |
720 ms |
48908 KB |
Output is correct |
26 |
Correct |
520 ms |
37448 KB |
Output is correct |
27 |
Correct |
713 ms |
48756 KB |
Output is correct |
28 |
Correct |
719 ms |
48908 KB |
Output is correct |
29 |
Correct |
505 ms |
37372 KB |
Output is correct |
30 |
Correct |
465 ms |
36756 KB |
Output is correct |
31 |
Correct |
467 ms |
36944 KB |
Output is correct |
32 |
Correct |
659 ms |
47784 KB |
Output is correct |
33 |
Correct |
455 ms |
36452 KB |
Output is correct |
34 |
Correct |
6 ms |
31320 KB |
Output is correct |
35 |
Correct |
7 ms |
31324 KB |
Output is correct |
36 |
Correct |
6 ms |
31324 KB |
Output is correct |
37 |
Correct |
7 ms |
31324 KB |
Output is correct |
38 |
Correct |
9 ms |
31324 KB |
Output is correct |
39 |
Correct |
8 ms |
31324 KB |
Output is correct |
40 |
Correct |
8 ms |
31488 KB |
Output is correct |
41 |
Correct |
463 ms |
36440 KB |
Output is correct |
42 |
Correct |
476 ms |
36804 KB |
Output is correct |
43 |
Correct |
657 ms |
47700 KB |
Output is correct |
44 |
Correct |
456 ms |
36672 KB |
Output is correct |
45 |
Correct |
166 ms |
38484 KB |
Output is correct |
46 |
Correct |
160 ms |
38232 KB |
Output is correct |
47 |
Correct |
140 ms |
38224 KB |
Output is correct |
48 |
Correct |
144 ms |
38180 KB |
Output is correct |
49 |
Correct |
140 ms |
38096 KB |
Output is correct |
50 |
Correct |
142 ms |
38204 KB |
Output is correct |
51 |
Correct |
897 ms |
65716 KB |
Output is correct |
52 |
Correct |
902 ms |
66000 KB |
Output is correct |
53 |
Correct |
751 ms |
65364 KB |
Output is correct |
54 |
Correct |
755 ms |
65556 KB |
Output is correct |
55 |
Correct |
750 ms |
65552 KB |
Output is correct |
56 |
Correct |
162 ms |
35920 KB |
Output is correct |
57 |
Correct |
155 ms |
35984 KB |
Output is correct |
58 |
Correct |
182 ms |
38484 KB |
Output is correct |
59 |
Correct |
187 ms |
38552 KB |
Output is correct |
60 |
Correct |
158 ms |
38744 KB |
Output is correct |
61 |
Correct |
160 ms |
38736 KB |
Output is correct |
62 |
Correct |
141 ms |
35820 KB |
Output is correct |
63 |
Correct |
160 ms |
38480 KB |
Output is correct |
64 |
Correct |
184 ms |
38664 KB |
Output is correct |
65 |
Correct |
180 ms |
38620 KB |
Output is correct |
66 |
Correct |
172 ms |
38484 KB |
Output is correct |
67 |
Correct |
161 ms |
38712 KB |
Output is correct |
68 |
Correct |
177 ms |
38484 KB |
Output is correct |
69 |
Correct |
173 ms |
38484 KB |
Output is correct |
70 |
Correct |
172 ms |
38488 KB |
Output is correct |
71 |
Correct |
158 ms |
38240 KB |
Output is correct |
72 |
Correct |
166 ms |
38480 KB |
Output is correct |
73 |
Correct |
139 ms |
38188 KB |
Output is correct |
74 |
Correct |
141 ms |
38228 KB |
Output is correct |
75 |
Correct |
138 ms |
38164 KB |
Output is correct |
76 |
Correct |
142 ms |
38228 KB |
Output is correct |
77 |
Correct |
1041 ms |
67968 KB |
Output is correct |
78 |
Correct |
1032 ms |
67844 KB |
Output is correct |
79 |
Correct |
881 ms |
68696 KB |
Output is correct |
80 |
Correct |
886 ms |
68432 KB |
Output is correct |
81 |
Correct |
870 ms |
67156 KB |
Output is correct |
82 |
Correct |
880 ms |
67676 KB |
Output is correct |
83 |
Correct |
1051 ms |
68180 KB |
Output is correct |
84 |
Correct |
1055 ms |
68068 KB |
Output is correct |
85 |
Correct |
966 ms |
67876 KB |
Output is correct |
86 |
Correct |
973 ms |
67984 KB |
Output is correct |
87 |
Correct |
990 ms |
67152 KB |
Output is correct |
88 |
Correct |
906 ms |
67904 KB |
Output is correct |