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 int long long
#define re(a, b, c, d) for (auto a = b; a <= c; a += d)
#define de(a, b, c, d) for (auto a = b; a >= c; a -= d)
#define ms (a); memset (a, 0, sizeof a);
#define imax INT_MAX
#define imin INT_MIN
#define wh(a) while (a --)
#define PII pair <int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define lson (x << 1)
#define rson lson + 1
template <typename T> bool chkmin (T& a, T b) {
return (b < a) ? a = b, 1 : 0;
}
template <typename T> bool chkmax (T& a, T b) {
return (b > a) ? a = b, 1 : 0;
}
using namespace std;
const int N = 1e6 + 5;
int T, n, m, q, s[N], e[N], mn[N << 2], tag[N << 2], ans[N];
vector <int> g[N], que[N];
void down (int x) {
chkmax (tag[lson], tag[x]);
chkmax (tag[rson], tag[x]);
chkmax (mn[lson], tag[x]);
chkmax (mn[rson], tag[x]);
tag[x] = 0;
}
void upd (int x, int l, int r, int L, int R, int val) {
if (L <= l && r <= R) {
chkmax (mn[x], val);
chkmax (tag[x], val);
return;
}
down (x);
int mid = l + r >> 1;
if (mid >= L) upd (lson, l, mid, L, R, val);
if (mid + 1 <= R) upd (rson, mid + 1, r, L, R, val);
mn[x] = min (mn[lson], mn[rson]);
}
int qry (int x, int l, int r, int L, int R) {
if (r < L || l > R) return 1e9;
if (L <= l && r <= R) return mn[x];
int mid = l + r >> 1;
down (x);
return min (qry (lson, l, mid, L, R), qry (rson, mid + 1, r, L, R));
}
signed main () {
cout << fixed << setprecision (0);
ios :: sync_with_stdio (0), cin.tie (0), cout.tie (0);
cin >> n >> m >> q;
int x, y;
re (i, 1, m, 1) cin >> x >> y, g[y].pb (x);
re (i, 1, q, 1) cin >> s[i] >> e[i], que[e[i]].pb (i);
re (i, 1, n, 1) {
for (int l : g[i]) upd (1, 1, n, l, i, l);
for (int k : que[i]) if (qry (1, 1, n, s[k], i) >= s[k]) ans[k] = 1;
}
re (i, 1, q, 1) {
if (ans[i]) cout << "YES";
else cout << "NO";
cout << "\n";
}
return 0;
}
Compilation message (stderr)
curtains.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
curtains.cpp:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int mid = l + r >> 1;
| ~~^~~
curtains.cpp: In function 'long long int qry(long long int, long long int, long long int, long long int, long long int)':
curtains.cpp:49:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int mid = l + r >> 1;
| ~~^~~
# | 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... |