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>
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
const int MAXN = 6e5 + 5;
#define ALL(a) (a).begin(), (a).end()
#define LB(a, x) (lower_bound(ALL(a), x) - (a).begin() + 1)
struct student {
    int x, y, z;
    student(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
};
struct query {
    int x, y, z, p;
    query(int x = 0, int y = 0, int z = 0, int p = 0) : x(x), y(y), z(z), p(p) {}
};
struct node {
    int N;
    vector<int> value;
    vector<int> BIT;
    node(int N = 0, vector<int> value = vector<int>(), vector<int> BIT = vector<int>()) : N(N), value(value), BIT(BIT) {}
    void init() {
        sort(ALL(value));
        value.resize(unique(ALL(value)) - value.begin());
        N = value.size() + 5;
        BIT.assign(N + 1, 0);
    }
    void update(int x) {
        x = LB(value, x);
        for(; x; x -= (x & -x)) BIT[x]++;
    }
    int get(int x) {
        x = LB(value, x);
        int res = 0;
        for(; x <= N; x += (x & -x))
            res += BIT[x];
        return res;
    }
};
int N, Q;
student a[MAXN];
query b[MAXN];
int ans[MAXN];
struct segment_tree {
    int N;
    node tree[MAXN * 4];
    void init(int _N) {
        N = _N;
    }
    void build() {
        for(int i = 1; i <= 4 * N ; i++) {
            tree[i].init();
        }
    }
    void update(int id, int l, int r, int p, int x) {
        if(r < p or l > p) return;
        tree[id].update(x);
        if(l == r) return;
        int m = (l + r) / 2;
        update(id * 2, l, m, p, x);
        update(id * 2 + 1, m + 1, r, p, x);
    }
    void update(int p, int x) {
        return update(1, 1, N, p, x);
    }
    int get(int id, int l, int r, int u, int v, int x) {
        if(r < u or l > v) return 0;
        if(u <= l and r <= v) {
            return tree[id].get(x);
        }
        int m = (l + r) / 2;
        return get(id * 2, l, m, u, v, x) + get(id * 2 + 1, m + 1, r, u, v, x);
    }
    int get(int l, int r, int x) {
        return get(1, 1, N, l, r, x);
    }
} ST;
signed main() {
#define TASK ""
    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> Q;
    for(int i = 1; i <= N; i++) {
        auto &[x, y, z] = a[i];
        cin >> x >> y;
        z = x + y;
    }
    for(int i = 1; i <= Q; i++) {
        auto &[x, y, z, p] = b[i];
        cin >> x >> y >> z;
        p = i;
    }
    vector<int> comp;
    for(int i = 1; i <= N; i++) {
        auto [x, y, z] = a[i];
        comp.emplace_back(x);
        comp.emplace_back(y);
        comp.emplace_back(z);
    }
    for(int i = 1; i <= Q; i++) {
        auto [x, y, z, p] = b[i];
        comp.emplace_back(x);
        comp.emplace_back(y);
        comp.emplace_back(z);
    }
    sort(ALL(comp));
    comp.resize(unique(ALL(comp)) - comp.begin());
    const int M = comp.size();
    for(int i = 1; i <= N; i++) {
        auto &[x, y, z] = a[i];
        x = LB(comp, x);
        y = LB(comp, y);
        z = LB(comp, z);
    }
    for(int i = 1; i <= Q; i++) {
        auto &[x, y, z, p] = b[i];
        x = LB(comp, x);
        y = LB(comp, y);
        z = LB(comp, z);
    }
    ST.init(M);
    for(int i = 1; i <= N; i++) {
        int id = 1, l = 1, r = M;
        int p = a[i].x;
        int v = a[i].y;
        while(l < r) {
            int m = (l + r) / 2;
            if(p <= m) {
                id = id * 2;
                r = m;
            } else {
                id = id * 2 + 1;
                l = m + 1;
            }
        }
        while(id >= 1) {
            ST.tree[id].value.emplace_back(v);
            id >>= 1;
        }
    }
    ST.build();
    sort(a + 1, a + N + 1, [&](const student a, const student b) {
        if(a.z != b.z) return a.z > b.z;
        if(a.x != b.x) return a.x > b.x;
        return a.y > b.y;
    });
    sort(b + 1, b + Q + 1, [&](const query a, const query b) {
        if(a.z != b.z) return a.z > b.z;
        if(a.x != b.x) return a.x > b.x;
        if(a.y != b.y) return a.y > b.y;
        return a.p > b.p;
    });
    int j = 1;
    for(int i = 1; i <= Q; i++) {
        while(j <= N and a[j].z >= b[i].z) {
            ST.update(a[j].x, a[j].y);
            j++;
        }
        ans[b[i].p] = ST.get(b[i].x, M, b[i].y);
    }
    for(int i = 1; i <= Q; i++) cout << ans[i] << "\n";
    return (0 ^ 0);
}
Compilation message (stderr)
examination.cpp: In function 'int main()':
examination.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(TASK ".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... |