This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define all(c)              (c).begin(), (c).end()
#define rall(c)             (c).rbegin(), (c).rend()
#define traverse(c, it)     for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N)           for(int i = 0; i < (N); ++i)
#define rrep(i, N)          for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N)          for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e)       for(int i = (s); i <= (e); ++i)
#define rep3(i, s, e, d)    for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#ifdef DEBUG
#define debug(x...)         { \
                            ++dbg::depth; \
                            string dbg_vals = dbg::to_string(x); \
                            --dbg::depth; \
                            dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
                            }
#define light_debug(x)      { \
                            dbg::light = true; \
                            dbg::dout << __func__ << ":" << __LINE__; \
                            dbg::dout << "  " << #x << " = " << x << endl; \
                            dbg::light = false; \
                            }
#else
#define debug(x...)         42
#define light_debug(x)      42
#endif
using ll = long long;
template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
struct fenwick_tree {
    int n;
    vector<int> a;
    vector<int> u;
    fenwick_tree(int n_ = 0) : n{n_}, a(n + 1) {}
    void update(int i) {
        for(++i; i <= n; i += i & -i)
            ++a[i], u.push_back(i);
    }
    int pref(int i) const {
        int s{};
        for(++i; i > 0; i -= i & -i)
            s += a[i];
        return s;
    }
    int query(int s, int e) const {
        return pref(e) - pref(s - 1);
    }
    void clear() {
        for(int x : u) a[x] = 0;
        u.clear();
    }
};
struct point {
    int x, y, z, i{-1};
};
namespace std {
    string to_string(const point& p) {
        ostringstream ss;
        ss << "{" << p.x << ", " << p.y << ", " << p.z << ", " << p.i << "}";
        return ss.str();
    }
};
#ifdef DEBUG
#include "debug.hpp"
#endif
int N, Q, M{};
vector<int> ans;
vector<point> points;
fenwick_tree bit;
using it = vector<point>::iterator;
void cdq_dnc(const it s, const it e) {
    if(e - s == 1) return;
    it m = s + (e - s) / 2;
    cdq_dnc(s, m), cdq_dnc(m, e);
    vector<point> tmp; tmp.reserve(e - s);
    for(auto i = s, j = m; i < m || j < e; ) {
        if(i != m && (j == e || i->y >= j->y)) {
            tmp.push_back(*i);
            if(i->i == -1)
                bit.update(i->z);
            ++i;
        } else {
            tmp.push_back(*j);
            if(j->i >= 0) 
                ans[j->i] += bit.query(j->z, M - 1);
            ++j;
        }
    }
    bit.clear();
    for(auto i = tmp.begin(), j = s; j < e; ++i, ++j)
        *j = *i;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef DEBUG
    freopen("debug", "w", stderr);
    #endif
    cin >> N >> Q; points.reserve(N + Q), ans.resize(Q);
    rep(i, N) {
        int S, T; cin >> S >> T;
        points.push_back(point{S, T, S + T, -1});
    }
    rep(i, Q) {
        int X, Y, Z; cin >> X >> Y >> Z;
        points.push_back(point{X, Y, Z, i});
    }
    sort(all(points), [](const point& p, const point& q) {
        return p.x > q.x || (p.x == q.x && p.y > q.y)
            || (p.x == q.x && p.y == q.y && p.z > q.z)
            || (p.x == q.x && p.y == q.y && p.z == q.z && p.i < q.i);
    });
    map<int, int> mp;
    for(const auto& p : points) mp[p.z];
    for(auto& p : mp) p.second = M++; 
    for(auto& p : points) p.z = mp[p.z];
    bit = fenwick_tree(M);
    cdq_dnc(all(points));
    
    rep(i, Q) cout << ans[i] << '\n';
    #ifdef DEBUG
    dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC  << "ms" << endl;
    #endif
    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... |