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 pb push_back
#define all(aa) aa.begin(), aa.end()
using namespace std;
struct BIT{
int n;
vector<int> cnt, fen;
BIT(vector<int> a) : cnt(a){
n = a.size();
fen.resize(n);
for(int i = 0; i < n; i++){
fen[i] += cnt[i];
upd(i);
}
}
void upd(int pos){
for(int j = pos; j < n; j = j|(j+1)){
fen[j] += 1;
}
}
int find(int pos){
int ret = 0;
for(int j = pos; j >= 0; j = (j & (j + 1)) - 1)
ret += fen[j];
return ret;
}
int find(int l, int r){
return find(r) - find(l - 1);
}
};
int main(){
int n, m, q;
cin >> n >> m >> q;
vector<int> cnt(n);
vector<int> ok(n);
vector<int> mn(n, n+1);
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
--a, --b;
mn[b] = min(mn[b], a);
if(a == 0) cnt[b] = 1;
}
BIT fen(cnt);
for(int i = 0; i < n; i++){
if(fen.find(mn[i], i) > 0){
ok[i] = 1;
fen.upd(i);
}
}
for(int i = 0; i < q; i++){
int a, b;
cin >> a >> b;
--a, --b;
cout << (ok[b] ? "YES" : "NO") << endl;
}
}
# | 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... |