#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define endl '\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define py cout << "YES" << endl;
#define pn cout << "NO" << endl;
#define pb push_back
#define int long long
typedef long double lld;
#define double lld
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 2e5;
vector<int>primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
// Check for queue, priorioty_queue, stack, ordered_set solutions
// stack => LIFO (whatever goes in last comes out last)
// queue => FIFO (whatever goes in first comes out first)
// priority_queue => Dynamic queries of minimum/maximum
// ordered_set => set in vector form
//[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element]
// To comment multiple lines : ctrl + /
// To find and replace : ctrl+H
void judge(){
srand(time(NULL));
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
freopen("2.txt","w",stdout);
freopen("Error.txt", "w", stderr);
#define debug(x...) cerr << #x <<" = "; _print(x); cerr << endl;
#else
#define debug(x...)
#endif
}
void usaco(string s) {
freopen((s + ".in").c_str(),"r",stdin);
freopen((s + ".out").c_str(),"w",stdout);
}
struct node {
int sum;
node(int x = 0){
sum = x;
}
};
struct lazyNode {
bool is_set = false; // Flag for set operation
int set_val = -1*inf; // Value for the set operation
};
node unite(node a, node b) {
return node(min(a.sum,b.sum));
}
class LazySegmentTree {
private:
vector<node> t;
vector<lazyNode> lazy;
int n;
vector<int>a;
#define mid (start+end)/2
#define lc x + 1
#define rc 2*(mid-start+1)+x
void build(int x, int start, int end) {
if (start == end) {
t[x]= node(-1);
return;
}
build(lc, start, mid);
build(rc, mid + 1, end);
t[x] = unite(t[lc], t[rc]);
}
void push(int x, int start, int end) { // MAKE CHANGES HERE
if (lazy[x].is_set) {
t[x].sum = max(t[x].sum,lazy[x].set_val);
if (start != end) {
lazy[lc].is_set = true;
lazy[rc].is_set = true;
lazy[lc].set_val = max(lazy[lc].set_val,lazy[x].set_val);
lazy[rc].set_val = max(lazy[rc].set_val,lazy[x].set_val);
}
lazy[x].is_set = false;
lazy[x].set_val = -1*inf;
}
}
void set(int x, int start, int end, int l, int r, int val) {
push(x, start, end);
if(l<=start and end<=r){
lazy[x].is_set = true;
lazy[x].set_val = max(lazy[x].set_val,val);
push(x,start,end);
return;
}
if(r<=mid){
push(rc,mid+1,end);
set(lc,start,mid,l,r,val);
}
else if(mid<l){
push(lc,start,mid);
set(rc,mid+1,end,l,r,val);
}
else{
set(lc,start,mid,l,r,val);
set(rc,mid+1,end,l,r,val);
}
t[x] = unite(t[lc], t[rc]);
}
node query(int x, int start, int end, int l, int r) {
push(x, start, end);
if (l <= start && end<=r) {
return t[x];
}
if(r<=mid){
return query(lc,start,mid,l,r);
}
else if(mid<l){
return query(rc,mid+1,end,l,r);
}
else{
return unite(query(lc,start,mid,l,r),query(rc,mid+1,end,l,r));
}
}
public:
void build(vector<int>&tmp) {
n = tmp.size();
a = tmp;
t.resize(2 * n);
lazy.resize(2 * n);
build(0, 0, n - 1);
}
void set(int l, int r) {
set(0, 0, n - 1, l, r, l);
}
node query(int l, int r) {
node result = query(0, 0, n - 1, l, r);
return result;
}
};
signed main(){
fastio; //judge();
int n,m,q; cin >> n >> m >> q;
vector<vector<int>>end(n);
for(int i = 0,u,v;i<m;i++){
cin >> u >> v; u--; v--;
end[v].pb(u);
}
vector<vector<pair<int,int>>>queries(n);
for(int i = 0,u,v;i<q;i++){
cin >> u >> v; u--; v--;
queries[v].pb({u,i});
}
vector<bool>result(q,false);
vector<int>tmp(n); LazySegmentTree seg;
seg.build(tmp);
for(int i = 0;i<n;i++){
for(auto x : end[i]){
seg.set(x,i);
}
for(auto [pos,idx] : queries[i]){
result[idx] = (seg.query(pos,i).sum==pos);
}
}
for(int i = 0;i<q;i++){
if(result[i]){
py;
}
else{
pn;
}
}
}
Compilation message (stderr)
curtains.cpp: In function 'void judge()':
curtains.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen("1.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
curtains.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen("2.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
curtains.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | freopen("Error.txt", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp: In function 'void usaco(std::string)':
curtains.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen((s + ".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
curtains.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen((s + ".out").c_str(),"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... |