#include <bits/stdc++.h>
using namespace std;
struct Segtree {
int n;
vector<int> st, lz;
Segtree(const int N) {
n = N;
st = vector<int>(4*n, 0);
lz = vector<int>(4*n, 0);
}
void push(int p, int l, int r) {
if (lz[p] == 0) return;
if (l != r) {
int m = (l+r)/2;
st[2*p] += lz[p];
st[2*p+1] += lz[p];
lz[2*p] += lz[p];
lz[2*p+1] += lz[p];
}
lz[p] = 0;
}
void add(int p, int l, int r, int i, int j, int v) {
if (i > j) return;
push(p, l, r);
if (l == i && r == j) {
st[p] += v;
lz[p] += v;
} else {
int m = (l+r)/2;
add(2*p, l, m, i, min(m, j), v);
add(2*p+1, m+1, r, max(m+1, i), j, v);
st[p] = min(st[2*p], st[2*p+1]);
}
}
int Min(int p, int l, int r, int i, int j) {
if (i > j) return 1e9;
push(p, l, r);
if (l == i && r == j) return st[p];
int m = (l+r)/2;
return min(Min(2*p, l, m, i, min(m, j)), Min(2*p+1, m+1, r, max(i, m+1), j));
}
void add(int i, int j, int v) { add(1, 0, n-1, i, j, v); }
int Min(int i, int j) { return Min(1, 0, n-1, i, j); }
};
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<pair<int, int>> curtains(m);
for (int i = 0; i < m; ++i) {
cin >> curtains[i].first >> curtains[i].second;
--curtains[i].first; --curtains[i].second;
}
vector<pair<pair<int, int>, int>> queries(q);
for (int i = 0; i < q; ++i) {
cin >> queries[i].first.first >> queries[i].first.second;
--queries[i].first.first; --queries[i].first.second;
queries[i].second = i;
}
sort(curtains.begin(), curtains.end());
sort(queries.begin(), queries.end());
vector<bool> used(m, false), ans_query(q);
Segtree Stage(n);
int last_used = 0;
for (int i = 0; i < q; ++i) {
int l = queries[i].first.first, r = queries[i].first.second;
for (int j = 0; j < m && curtains[j].first <= r; ++j) {
if (curtains[j].first >= l && curtains[j].second <= r) continue;
if (used[j]) Stage.add(curtains[j].first, curtains[j].second, -1);
used[j] = false;
}
for (int j = 0; j < m && curtains[j].first <= r; ++j) {
if (curtains[j].first < l) continue;
if (curtains[j].second <= r) {
if (!used[j]) Stage.add(curtains[j].first, curtains[j].second, 1);
used[j] = true;
}
}
ans_query[queries[i].second] = (Stage.Min(l, r)>0);
}
for (int i = 0; i < q; ++i) {
if (ans_query[i]) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
Compilation message
curtains.cpp: In member function 'void Segtree::push(int, int, int)':
curtains.cpp:18:17: warning: unused variable 'm' [-Wunused-variable]
18 | int m = (l+r)/2;
| ^
curtains.cpp: In function 'int main()':
curtains.cpp:75:9: warning: unused variable 'last_used' [-Wunused-variable]
75 | int last_used = 0;
| ^~~~~~~~~
# |
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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
103 ms |
348 KB |
Output is correct |
14 |
Correct |
107 ms |
348 KB |
Output is correct |
15 |
Correct |
100 ms |
544 KB |
Output is correct |
16 |
Correct |
89 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
568 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
348 KB |
Output is correct |
21 |
Correct |
17 ms |
568 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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
103 ms |
348 KB |
Output is correct |
14 |
Correct |
107 ms |
348 KB |
Output is correct |
15 |
Correct |
100 ms |
544 KB |
Output is correct |
16 |
Correct |
89 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
568 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
348 KB |
Output is correct |
21 |
Correct |
17 ms |
568 KB |
Output is correct |
22 |
Execution timed out |
1567 ms |
10648 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1594 ms |
9528 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
103 ms |
348 KB |
Output is correct |
14 |
Correct |
107 ms |
348 KB |
Output is correct |
15 |
Correct |
100 ms |
544 KB |
Output is correct |
16 |
Correct |
89 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
568 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
348 KB |
Output is correct |
21 |
Correct |
17 ms |
568 KB |
Output is correct |
22 |
Execution timed out |
1587 ms |
4436 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
103 ms |
348 KB |
Output is correct |
14 |
Correct |
107 ms |
348 KB |
Output is correct |
15 |
Correct |
100 ms |
544 KB |
Output is correct |
16 |
Correct |
89 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
568 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
348 KB |
Output is correct |
21 |
Correct |
17 ms |
568 KB |
Output is correct |
22 |
Execution timed out |
1567 ms |
10648 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |