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>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
//#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define pb push_back
#define N 2005
#define M 500005
const int INF = 1e9 + 7;
int32_t main(){
//fileio();
fastio();
int n, m, q;
cin>>n>>m>>q;
if (n <= 2000){
vector<bitset<N>> dp(n + 5, 0);
vector<int> l(m + 5, 0), r(m + 5, 0), ans(q + 5, 0);
vector<vector<int>> ex(n + 5);
vector<vector<pii>> todo(n + 5);
for (int i = 1; i <= m; i++){
cin>>l[i]>>r[i];
ex[l[i]].pb(r[i]);
}
for (int i = 1; i <= q; i++){
int s, e;
cin>>s>>e;
todo[s].pb({e, i});
}
for (int i = n; i >= 1; i--){
sort(ex[i].begin(), ex[i].end());
int last = i;
bitset<N> all(0);
all = ~all;
for (auto j : ex[i]){
dp[i][j] = 1;
for (int k = last; k < j; k++) all[k] = 0;
while(last <= j){
last++;
//cout<<last<<sp<<all<<endl;
dp[i] |= dp[last] & all;
}
last--;
}
//cout<<i<<": "<<dp[i]<<endl;
for (auto j : todo[i]){
if (dp[i][j.st]) ans[j.nd] = 1;
}
}
for (int i = 1; i <= q; i++) {
if (ans[i]) cout<<"YES\n";
else cout<<"NO\n";
}
}
else{
vector<bitset<M>> dp(n + 5, 0);
vector<int> l(m + 5, 0), r(m + 5, 0), ans(q + 5, 0);
vector<vector<int>> ex(n + 5);
vector<vector<pii>> todo(n + 5);
for (int i = 1; i <= m; i++){
cin>>l[i]>>r[i];
ex[l[i]].pb(r[i]);
}
for (int i = 1; i <= q; i++){
int s, e;
cin>>s>>e;
todo[s].pb({e, i});
}
for (int i = n; i >= 1; i--){
sort(ex[i].begin(), ex[i].end());
int last = i;
bitset<M> all(0);
all = ~all;
for (auto j : ex[i]){
dp[i][j] = 1;
for (int k = last; k < j; k++) all[k] = 0;
while(last <= j){
last++;
//cout<<last<<sp<<all<<endl;
dp[i] |= dp[last] & all;
}
last--;
}
//cout<<i<<": "<<dp[i]<<endl;
for (auto j : todo[i]){
if (dp[i][j.st]) ans[j.nd] = 1;
}
}
for (int i = 1; i <= q; i++) {
if (ans[i]) cout<<"YES\n";
else cout<<"NO\n";
}
}
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# | 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... |