# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1169628 | Thanhs | Curtains (NOI23_curtains) | C++20 | 23 ms | 47432 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#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 inf = 1e9;
int n, m, q, ans[NM];
set<int> s[NM];
vector<int> dt[NM];
pair<int, int> a[NM];
vector<pair<int, int>> Q[NM];
bool b[NM], f[NM];
void add(int i, int v)
{
i = n - i + 1;
for (; i <= n; i += i & -i)
dt[i].push_back(v);
}
void del(int i)
{
i = n - i + 1;
for (; i <= n; i += i & -i)
dt[i].pop_back();
}
int get(int i)
{
i = n - i + 1;
int res = inf;
for (; i; i -= i & -i)
if (dt[i].size())
setmin(res, dt[i].back());
return res;
}
void bu(int x)
{
}
void merge(int x, int y)
{
if (s[x].size() < s[y].size())
swap(s[x], s[y]);
for (auto t : s[y])
s[x].insert(t);
}
void solve()
{
cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
cin >> a[i].fi >> a[i].se;
for (int i = 1; i <= q; i++)
{
int l, r;
cin >> l >> r;
Q[l].emplace_back(r, i);
}
sort(a + 1, a + 1 + m);
for (int i = 1; i <= m; i++)
{
f[i] = !b[a[i].fi];
b[a[i].fi] = 1;
}
for (int i = m; i >= 1; i--)
{
s[i].insert(a[i].se);
while (1)
{
int t = get(a[i].fi);
if (t == inf || a[t].fi > a[i].se + 1)
break;
merge(i, t);
del(a[t].fi);
}
if (f[i])
for (auto t : Q[a[i].fi])
if (t.fi >= a[i].se)
ans[t.se] = s[i].count(t.fi);
add(a[i].fi, i);
}
for (int i = 1; i <= q; i++)
cout << (ans[i] ? "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... |