#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define MASK(i) (1LL << (i))
template<typename t1, typename t2> bool maximize(t1 &a, t2 b){
if(a < b) a = b; else return 0; return 1;
}
template<typename t1, typename t2> bool minimize(t1 &a, t2 b){
if(a > b) a = b; else return 0; return 1;
}
#define file "anhdep"
const int maxn = 1e5 + 5;
const int oo = 1e9;
const ll OO = 1e18;
const int MOD = 1e9 + 7;
int n, q;
pii a[maxn];
bool oksub2;
vector<int> comnum;
struct item{
int x, y, z, id;
item(){}
item(int a, int b, int c, int d){
x = a, y = b, z = c, id = d;
}
};
item query[maxn];
void input(){
cin >> n >> q;
oksub2 = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i].fi >> a[i].se;
}
for(int i = 1; i <= q; i++){
cin >> query[i].x >> query[i].y >> query[i].z;
query[i].id = i;
if(query[i].z != 0)
oksub2 = 0;
}
}
namespace sub1{
void sol(){
for(int i = 1; i <= q; i++){
int x = query[i].x;
int y = query[i].y;
int z = query[i].z;
int ans = 0;
for(int j = 1 ; j <= n; j++)
ans += (a[j].fi >= x) && (a[j].se >= y) && (a[j].fi + a[j].se >= z);
cout << ans << '\n';
}
}
}
namespace sub2{
int ans[maxn];
const int lmt = 1e5 + 1;
struct fenwick{
int fw[maxn];
fenwick(){
memset(fw, 0, sizeof(fw));
}
void update(int id, int val){
id++;
id = lmt - id + 1;
for(;id <= lmt; id += id & -id) fw[id] += val;
}
int get(int id){
id++;
id = lmt - id + 1;
int ret = 0;
for(;id > 0; id -= id & -id) ret += fw[id];
return ret;
}
} tree;
bool cmp(item a, item b){
if(a.x == b.x) return a.y > b.y;
return a.x > b.x;
}
void sol(){
sort(a + 1, a + 1 + n, greater<pii>());
sort(query + 1, query + 1 + q, cmp);
int p = 1;
for(int i = 1; i <= q; i++){
int x = query[i].x;
int y = query[i].y;
int z = query[i].z;
int id = query[i].id;
while(p <= n && a[p].fi >= x){
tree.update(a[p].se, 1);
p++;
}
ans[id] = tree.get(y);
}
for(int i = 1; i <= q; i++){
cout << ans[i] << '\n';
}
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
input();
if(max(n, q) <= 3000)
sub1::sol();
else if(oksub2)
sub2::sol();
else
sub1::sol();
return 0;
}
# | 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... |