#include <bits/stdc++.h>
#define int long long int
#define MP make_pair
#define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
#define pb push_back
const int N = 5e5+5;
const int M = 5e5 + 5;
const int MOD = 1e9+7;
const int INF = 1e17;
using namespace std;
void fastio() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int n,m,q;
struct Query {
int l, r, id;
Query() : l(0), r(0), id(0) {};
Query(int lf, int rg, int i) : l(lf), r(rg), id(i) {};
void input(int ind) {
id = ind;
cin>>l>>r;
}
const bool operator<(const Query &oth) {
return r < oth.r;
}
};
struct Node {
int cnt, mn, lazy;
Node() : cnt(0), mn(INF), lazy(0) {};
Node(int c, int m) : cnt(c), mn(m), lazy(0) {};
Node comb(Node &x) {
if(x.mn == mn) return Node(cnt + x.cnt, mn);
if(x.mn > mn) return Node(cnt, mn);
return Node(x.cnt, x.mn);
}
};
struct SegTree {
vector<Node> data;
int sz;
void build(int tl, int tr, int v) {
if(tl == tr) {
data[v] = Node(1,0);
return;
}
int tm = (tl + tr) >> 1;
build(tl, tm, v*2);
build(tm + 1, tr, v*2+1);
data[v] = data[v*2].comb(data[v*2+1]);
}
SegTree(int sz) {
this->sz = sz;
data.assign(4*(sz + 5), Node());
build(1, sz, 1);
}
void push(int v) {
data[v*2].lazy += data[v].lazy;
data[v*2].mn += data[v].lazy;
data[v*2+1].lazy += data[v].lazy;
data[v*2+1].mn += data[v].lazy;
data[v].lazy = 0;
}
void update(int tl, int tr, int v, int l, int r, int val) {
if(tl >= l && tr <= r) {
data[v].mn += val;
data[v].lazy += val;
return;
}
if(tl > r || tr < l) {
return;
}
push(v);
int tm = (tl + tr) >> 1;
update(tl, tm, v*2, l, r, val);
update(tm + 1, tr, v*2+1, l, r, val);
data[v] = data[v*2].comb(data[v*2+1]);
}
void update(int l, int r, int val) {
update(1, sz, 1, l, r, val);
}
int query(int tl, int tr, int v, int l, int r) {
if(tl >= l && tr <= r) {
if(data[v].mn == 0) {
return data[v].cnt;
}
return 0;
}
if(tl > r || tr < l) {
return 0;
}
push(v);
int tm = (tl + tr) >> 1;
return query(tl, tm, v*2, l, r) + query(tm + 1, tr, v*2+1, l, r);
}
int query(int l, int r) {
return query(1, sz, 1, l, r);
}
};
vector<Query> curt; // l, r
vector<Query> quer;
vector<bool> res(N, 0);
void solve() {
cin>>n>>m>>q;
curt.resize(m);
quer.resize(q);
REP(i,m) {
curt[i].input(i + 1);
}
REP(i,q) {
quer[i].input(i + 1);
}
sort(quer.begin(), quer.end());
sort(curt.begin(), curt.end());
SegTree st(n);
int ind = 0;
for(int i = 0; i<q; i++) {
while(ind < m && curt[ind].r <= quer[i].r) {
st.update(curt[ind].l, curt[ind].r, 1);
ind++;
}
int cnt = st.query(1, quer[i].r);
// cout<<"cnt:"<<cnt<<"id:"<<quer[i].id<<"\n";
res[quer[i].id] = (cnt == 0);
}
for(int i = 1; i<=q; i++) {
// cout<<res[i]<<" wtf\n";
if(res[i]) cout<<"YES";
else cout<<"NO";
cout<<"\n";
}
}
signed main() {
// fastio();
solve();
}
Compilation message
curtains.cpp: In function 'void solve()':
curtains.cpp:5:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
5 | #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
| ^
curtains.cpp:118:5: note: in expansion of macro 'REP'
118 | REP(i,m) {
| ^~~
curtains.cpp:5:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
5 | #define REP(i,n) for(int (i) = 0; (i)<(n); (i)++)
| ^
curtains.cpp:121:5: note: in expansion of macro 'REP'
121 | REP(i,q) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
209 ms |
14392 KB |
Output is correct |
9 |
Correct |
239 ms |
15444 KB |
Output is correct |
10 |
Correct |
493 ms |
25940 KB |
Output is correct |
11 |
Correct |
208 ms |
14420 KB |
Output is correct |
12 |
Correct |
138 ms |
14928 KB |
Output is correct |
13 |
Correct |
141 ms |
14932 KB |
Output is correct |
14 |
Correct |
122 ms |
14664 KB |
Output is correct |
15 |
Correct |
120 ms |
14644 KB |
Output is correct |
16 |
Correct |
120 ms |
14644 KB |
Output is correct |
17 |
Correct |
126 ms |
14652 KB |
Output is correct |
18 |
Correct |
828 ms |
72528 KB |
Output is correct |
19 |
Correct |
864 ms |
72468 KB |
Output is correct |
20 |
Correct |
724 ms |
72208 KB |
Output is correct |
21 |
Correct |
848 ms |
72212 KB |
Output is correct |
22 |
Correct |
695 ms |
72368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |