#include <bits/stdc++.h>
using namespace std;
#define tol(bi) (1LL<<((int)(bi)))
typedef long long ll;
constexpr int MOD = 1e9+7;
constexpr int MAXN = 2000005;
struct SegTree{
vector<int> segtree;
SegTree(int n){
segtree.resize(tol(ceil(log2(n)+1))-1,-1);
}
void dallan(int node){
if (node*2+1<segtree.size()){
segtree[node*2+1]=max(segtree[node*2+1],segtree[node]);
segtree[node*2+2]=max(segtree[node*2+2],segtree[node]);
}
}
void update(int tarl, int tarr, int val, int l = 0, int r = -1, int node = 0){
if (r==-1) r = segtree.size()/2;
dallan(node);
if (l>=tarl && r<=tarr){
segtree[node]=max(segtree[node],val);
dallan(node);
return;
}
if (l>tarr || r<tarl) return;
int mid = l+(r-l)/2;
if (mid>=tarl) update(tarl, tarr, val, l, mid, node*2+1);
if (mid+1<=tarr) update(tarl, tarr, val, mid+1, r, node*2+2);
segtree[node]=min(segtree[node*2+1],segtree[node*2+2]);
}
int query(int tarl, int tarr, int l = 0, int r = -1, int node = 0){
if (r==-1) r = segtree.size()/2;
dallan(node);
if (l>=tarl && r<=tarr) return segtree[node];
if (l>tarr || r<tarl) return MOD;
int mid = l+(r-l)/2;
int lnode = MOD;
int rnode = MOD;
if (mid>=tarl) lnode = query(tarl, tarr, l, mid, node*2+1);
if (mid+1<=tarr) rnode = query(tarl, tarr, mid+1, r, node*2+2);
return min(lnode, rnode);
}
};
int main(){
int n,m,q;
cin>>n>>m>>q;
SegTree segtree(n);
vector<pair<int,int>> arr(m);
for (int i = 0; i < m; ++i)
{
cin>>arr[i].first>>arr[i].second;
}
sort(arr.begin(), arr.end(), [&](pair<int,int> a, pair<int,int> b){
return a.second<b.second;
});
int ind = 0;
vector<array<int,3>> qarr(q);
vector<bool> ansarr(q,false);
for (int i = 0; i < q; ++i)
{
cin>>qarr[i][0]>>qarr[i][1];
qarr[i][2]=i;
}
sort(qarr.begin(), qarr.end(), [&](array<int,3> a, array<int,3> b){
return a[1]<b[1];
});
for (int i = 0; i < q; ++i)
{
while (ind<m && arr[ind].second<=qarr[i][1]){
segtree.update(arr[ind].first-1,arr[ind].second-1,arr[ind].first-1);
ind++;
}
if (segtree.query(qarr[i][0]-1,qarr[i][1]-1)>=qarr[i][0]-1) ansarr[qarr[i][2]]=true;
}
for (int i = 0; i < q; ++i)
{
if (ansarr[i]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
Compilation message
curtains.cpp: In member function 'void SegTree::dallan(int)':
curtains.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if (node*2+1<segtree.size()){
| ~~~~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
484 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
5 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 |
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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
484 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
891 ms |
7856 KB |
Output is correct |
23 |
Correct |
858 ms |
8324 KB |
Output is correct |
24 |
Correct |
902 ms |
9080 KB |
Output is correct |
25 |
Correct |
1130 ms |
12072 KB |
Output is correct |
26 |
Correct |
895 ms |
8140 KB |
Output is correct |
27 |
Correct |
1202 ms |
12432 KB |
Output is correct |
28 |
Correct |
1159 ms |
12256 KB |
Output is correct |
29 |
Correct |
837 ms |
8020 KB |
Output is correct |
30 |
Correct |
780 ms |
8136 KB |
Output is correct |
31 |
Correct |
860 ms |
8512 KB |
Output is correct |
32 |
Correct |
1117 ms |
12352 KB |
Output is correct |
33 |
Correct |
776 ms |
8276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
348 KB |
Output is correct |
7 |
Correct |
4 ms |
348 KB |
Output is correct |
8 |
Correct |
763 ms |
8196 KB |
Output is correct |
9 |
Correct |
903 ms |
8520 KB |
Output is correct |
10 |
Correct |
1088 ms |
12080 KB |
Output is correct |
11 |
Correct |
793 ms |
8240 KB |
Output is correct |
12 |
Correct |
248 ms |
3740 KB |
Output is correct |
13 |
Correct |
246 ms |
3788 KB |
Output is correct |
14 |
Correct |
227 ms |
3848 KB |
Output is correct |
15 |
Correct |
220 ms |
3516 KB |
Output is correct |
16 |
Correct |
224 ms |
3664 KB |
Output is correct |
17 |
Correct |
219 ms |
3516 KB |
Output is correct |
18 |
Correct |
1331 ms |
15912 KB |
Output is correct |
19 |
Correct |
1303 ms |
16212 KB |
Output is correct |
20 |
Correct |
1144 ms |
15828 KB |
Output is correct |
21 |
Correct |
1153 ms |
15656 KB |
Output is correct |
22 |
Correct |
1165 ms |
15872 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 |
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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
484 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
245 ms |
2664 KB |
Output is correct |
23 |
Correct |
252 ms |
2896 KB |
Output is correct |
24 |
Correct |
282 ms |
3524 KB |
Output is correct |
25 |
Correct |
279 ms |
3824 KB |
Output is correct |
26 |
Correct |
245 ms |
3784 KB |
Output is correct |
27 |
Correct |
244 ms |
3796 KB |
Output is correct |
28 |
Correct |
214 ms |
3156 KB |
Output is correct |
29 |
Correct |
240 ms |
3592 KB |
Output is correct |
30 |
Correct |
271 ms |
3668 KB |
Output is correct |
31 |
Correct |
272 ms |
3516 KB |
Output is correct |
32 |
Correct |
305 ms |
3524 KB |
Output is correct |
33 |
Correct |
251 ms |
3676 KB |
Output is correct |
34 |
Correct |
268 ms |
3664 KB |
Output is correct |
35 |
Correct |
278 ms |
3736 KB |
Output is correct |
36 |
Correct |
253 ms |
3512 KB |
Output is correct |
37 |
Correct |
253 ms |
3788 KB |
Output is correct |
38 |
Correct |
248 ms |
3664 KB |
Output is correct |
39 |
Correct |
225 ms |
3668 KB |
Output is correct |
40 |
Correct |
229 ms |
3680 KB |
Output is correct |
41 |
Correct |
224 ms |
3668 KB |
Output is correct |
42 |
Correct |
221 ms |
3528 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 |
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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
344 KB |
Output is correct |
14 |
Correct |
5 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
7 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
5 ms |
484 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
891 ms |
7856 KB |
Output is correct |
23 |
Correct |
858 ms |
8324 KB |
Output is correct |
24 |
Correct |
902 ms |
9080 KB |
Output is correct |
25 |
Correct |
1130 ms |
12072 KB |
Output is correct |
26 |
Correct |
895 ms |
8140 KB |
Output is correct |
27 |
Correct |
1202 ms |
12432 KB |
Output is correct |
28 |
Correct |
1159 ms |
12256 KB |
Output is correct |
29 |
Correct |
837 ms |
8020 KB |
Output is correct |
30 |
Correct |
780 ms |
8136 KB |
Output is correct |
31 |
Correct |
860 ms |
8512 KB |
Output is correct |
32 |
Correct |
1117 ms |
12352 KB |
Output is correct |
33 |
Correct |
776 ms |
8276 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
440 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
7 ms |
348 KB |
Output is correct |
39 |
Correct |
4 ms |
348 KB |
Output is correct |
40 |
Correct |
4 ms |
348 KB |
Output is correct |
41 |
Correct |
763 ms |
8196 KB |
Output is correct |
42 |
Correct |
903 ms |
8520 KB |
Output is correct |
43 |
Correct |
1088 ms |
12080 KB |
Output is correct |
44 |
Correct |
793 ms |
8240 KB |
Output is correct |
45 |
Correct |
248 ms |
3740 KB |
Output is correct |
46 |
Correct |
246 ms |
3788 KB |
Output is correct |
47 |
Correct |
227 ms |
3848 KB |
Output is correct |
48 |
Correct |
220 ms |
3516 KB |
Output is correct |
49 |
Correct |
224 ms |
3664 KB |
Output is correct |
50 |
Correct |
219 ms |
3516 KB |
Output is correct |
51 |
Correct |
1331 ms |
15912 KB |
Output is correct |
52 |
Correct |
1303 ms |
16212 KB |
Output is correct |
53 |
Correct |
1144 ms |
15828 KB |
Output is correct |
54 |
Correct |
1153 ms |
15656 KB |
Output is correct |
55 |
Correct |
1165 ms |
15872 KB |
Output is correct |
56 |
Correct |
245 ms |
2664 KB |
Output is correct |
57 |
Correct |
252 ms |
2896 KB |
Output is correct |
58 |
Correct |
282 ms |
3524 KB |
Output is correct |
59 |
Correct |
279 ms |
3824 KB |
Output is correct |
60 |
Correct |
245 ms |
3784 KB |
Output is correct |
61 |
Correct |
244 ms |
3796 KB |
Output is correct |
62 |
Correct |
214 ms |
3156 KB |
Output is correct |
63 |
Correct |
240 ms |
3592 KB |
Output is correct |
64 |
Correct |
271 ms |
3668 KB |
Output is correct |
65 |
Correct |
272 ms |
3516 KB |
Output is correct |
66 |
Correct |
305 ms |
3524 KB |
Output is correct |
67 |
Correct |
251 ms |
3676 KB |
Output is correct |
68 |
Correct |
268 ms |
3664 KB |
Output is correct |
69 |
Correct |
278 ms |
3736 KB |
Output is correct |
70 |
Correct |
253 ms |
3512 KB |
Output is correct |
71 |
Correct |
253 ms |
3788 KB |
Output is correct |
72 |
Correct |
248 ms |
3664 KB |
Output is correct |
73 |
Correct |
225 ms |
3668 KB |
Output is correct |
74 |
Correct |
229 ms |
3680 KB |
Output is correct |
75 |
Correct |
224 ms |
3668 KB |
Output is correct |
76 |
Correct |
221 ms |
3528 KB |
Output is correct |
77 |
Correct |
1450 ms |
16208 KB |
Output is correct |
78 |
Execution timed out |
1518 ms |
29520 KB |
Time limit exceeded |
79 |
Halted |
0 ms |
0 KB |
- |