# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1169596 | Thanhs | Curtains (NOI23_curtains) | C++20 | 0 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 5e5 + 5;
const int LG = 20;
const int inf = 1e9;
int n, m, q, up[NM][LG], dt[NM], mn[NM];
pair<int, int> a[NM];
void upd(int i, int v)
{
i = n - i + 1;
for (; i <= n; i += i & -i)
setmin(dt[i], v);
}
int get(int i)
{
i = n - i + 1;
int res = inf;
for (; i; i -= i & -i)
setmin(res, dt[i]);
return res;
}
void solve()
{
cin >> n >> m >> q;
fill(dt + 1, dt + 1 + n, inf);
fill(mn + 1, mn + 1 + n, inf);
for (int i = 1; i <= m; i++)
cin >> a[i].fi >> a[i].se;
sort(a + 1, a + 1 + m, [&](const auto x, const auto y){return make_pair(x.se, x.fi) < make_pair(y.se, y.fi);});
for (int i = m; i >= 1; i--)
{
setmin(mn[a[i].fi], i);
up[i][0] = get(a[i].fi);
for (int j = 1; j < LG; j++)
up[i][j] = (up[i][j - 1] == inf ? inf : up[up[i][j - 1]][j - 1]);
upd(a[i].fi, i);
}
while (q--)
{
int l, r;
cin >> l >> r;
int t = mn[l];
if (t == inf)
cout << "NO\n";
else
{
for (int i = LG - 1; i >= 0; i--)
if (up[t][i] != inf && a[up[t][i]].se <= r)
t = up[t][i];
cout << (a[t].se == r ? "YES\n" : "NO\n");
}
}
}
signed main()
{
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
else if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
Compilation message (stderr)
# | 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... |