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 fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(5e5)+7;
const int inf = int(1e9)+7;
int n , m , q;
vector<int> event[maxN];
vector<ii> query[maxN];
struct node{
int val , lazy;
node(){
val = lazy = inf;
}
} st[4 * maxN];
#define lef(id) id * 2
#define rig(id) id * 2 + 1
void modify(int id , int x){
st[id].val = min(st[id].val , x);
st[id].lazy = min(st[id].lazy , x);
}
void down(int id , int l , int r){
int &x = st[id].lazy;
if (l == r) return;
modify(lef(id) , x);
modify(rig(id) , x);
}
void update(int id , int l , int r , int u , int v , int x){
if (v < l || r < u) return;
if (u <= l && r <= v){
modify(id , x);
//cout << l << " " << r << " " << st[id].val << "\n";
return;
}
down(id , l , r);
int mid = (l + r) / 2;
update(lef(id) , l , mid , u , v , x);
update(rig(id) , mid + 1 , r , u , v , x);
st[id].val = max(st[lef(id)].val , st[rig(id)].val);
}
int get(int id , int l , int r , int u , int v){
if (v < l || r < u) return -inf;
if (u <= l && r <= v) return st[id].val;
down(id , l , r);
int mid = (l + r) / 2;
return max(get(lef(id) , l , mid , u , v) , get(rig(id) , mid + 1 , r , u , v));
}
bool res[maxN];
void solve(){
cin >> n >> m >> q;
for (int i = 1 ; i <= m ; i++){
int l , r;
cin >> l >> r;
event[l].push_back(r);
}
for (int i = 1 ; i <= q ; i++){
int l , r;
cin >> l >> r;
query[l].push_back({r , i});
}
for (int i = n ; i >= 1 ; i--){
for (auto it : event[i]){
update(1 , 1 , n , i , it , it);
}
for (auto it : query[i]){
res[it.se] = (get(1 , 1 , n , i , it.fi) <= it.fi);
}
}
for (int i = 1 ; i <= q ; i++){
if (res[i]) cout << "YES\n"; else cout << "NO\n";
}
}
#define name "A"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
Compilation message (stderr)
curtains.cpp: In function 'int main()':
curtains.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(name".INP" , "r" , stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(name".OUT" , "w" , stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |