This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define lsb(x) (x &(-x))
using namespace std;
using pii = pair<int, int>;
const int N = 5e5 + 5;
int n, m, q, x, y, segm[N * 4], lz[N * 4];
void push (int l, int r, int idx) {
segm[idx] = max(segm[idx], lz[idx]);
if (l < r) {
lz[idx * 2 + 1] = max(lz[idx * 2 + 1], lz[idx]);
lz[idx * 2 + 2] = max(lz[idx * 2 + 2], lz[idx]);
}
lz[idx] = 0;
}
void upd (int l, int r, int idx, int tl, int tr, int val, int ckval) {
push(l, r, idx);
if (l > tr || r < tl || segm[idx] < ckval) return;
if (l >= tl && r <= tr) {
lz[idx] = max(lz[idx], val);
push(l, r, idx);
return;
}
int mid = (l + r) >> 1;
upd(l, mid, idx * 2 + 1, tl, tr, val, ckval);
upd(mid + 1, r, idx * 2 + 2, tl, tr, val, ckval);
segm[idx] = max(segm[idx * 2 + 1], segm[idx * 2 + 2]);
}
void upd2 (int l, int r, int idx, int pos, int val) {
push(l, r, idx);
if (l == r) return void(segm[idx] = max(segm[idx], val));
int mid = (l + r) >> 1;
if (pos <= mid) upd2(l, mid, idx * 2 + 1, pos, val);
else upd2(mid + 1, r, idx * 2 + 2, pos, val);
segm[idx] = max(segm[idx * 2 + 1], segm[idx * 2 + 2]);
}
int qr (int l, int r, int idx, int pos) {
push(l, r, idx);
if (l == r) return segm[idx];
int mid = (l + r) >> 1;
if (pos <= mid) return qr(l, mid, idx * 2 + 1, pos);
else return qr(mid + 1, r, idx * 2 + 2, pos);
}
int main() {
scanf("%d %d %d", &n, &m, &q);
vector<vector<int>> add(n + 5, vector<int>());
vector<vector<pii>> cq(n + 5, vector<pii>());
vector<int> ans(q);
for (int i = 0; i < m; i++) {
scanf("%d %d", &x, &y);
add[y].emplace_back(x);
}
for (int i = 0; i < q; i++) {
scanf("%d %d", &x, &y);
cq[y].emplace_back(x, i);
}
for (int i = 1; i <= n; i++) {
for (auto &e: add[i]) {
upd(1, n, 0, 1, n, i, e - 1);
upd2(1, n, 0, e, i);
}
for (auto &[x, y]: cq[i]) ans[y] = (qr(1, n, 0, x) == i);
}
for (auto &e: ans) printf("%s\n", e ? "YES" : "NO");
}
Compilation message (stderr)
curtains.cpp: In function 'int main()':
curtains.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d %d %d", &n, &m, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
curtains.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |