Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int M = 1e9 + 7;
const int N = 2e5 + 7;
const int K = 20;

vector <pair <int, int> > g[N][K];
bool u[N][K];
vector <int> ind, t;

void dfs(int i, int k)
{
    if (u[i][k])
    {
        return;
    }
    u[i][k] = true;
    for (auto to : g[i][k])
    {
        dfs(to.first, to.second);
    }
    if (k == 0)
    {
        ind.push_back(i);
    }
}

void zhfs(int i, int k)
{
    if (u[i][k])
    {
        return;
    }
    u[i][k] = true;
    for (auto to : g[i][k])
    {
        dfs(to.first, to.second);
    }
    if (k == 0)
    {
        t.push_back(i);
    }
}

int bin(int a, int n)
{
    if (!n)
    {
        return 1;
    }
    if (n % 2 == 0)
    {
        int t = bin(a, n / 2);
        return (t * (ll) t) % M;
    }
    else
    {
        return (a * (ll) bin(a, n - 1)) % M;
    }
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    vector <int> fact(n + 1), rfact(n + 1);
    fact[0] = 1;
    rfact[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        fact[i] = (fact[i - 1] * (ll) i) % M;
        rfact[i] = bin(fact[i], M - 2);
    }
    vector <pair <int, int> > d;
    for (int i = 0; i < n; i++)
    {
        int c, w;
        scanf("%d%d", &c, &w);
        d.push_back({w, c});
    }
    sort(d.begin(), d.end());
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < K; j++)
        {
            g[i][j].push_back({i, j - 1});
            if (i + (1 << (j - 1)) < n)
            {
                g[i][j].push_back({i + (1 << (j - 1)), j - 1});
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (d[0].first + d[i].first > y)
        {
            continue;
        }
        int l = 0, r = n;
        while (l < r - 1)
        {
            int m = (l + r) / 2;
            if (d[m].first + d[i].first <= y)
            {
                l = m;
            }
            else
            {
                r = m;
            }
        }
        int cur = 0;
        for (int p = K - 1; p >= 0; p--)
        {
            if (cur + (1 << p) - 1 <= l)
            {
                g[i][0].push_back({cur, p});
                cur += (1 << p);
            }
        }
    }
    memset(u, 0, sizeof u);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < K; j++)
        {
             zhfs(i, j);
        }
    }
    reverse(t.begin(), t.end());
    memset(u, 0, sizeof u);
    ll ans = 1;
    for (int i : t)
    {
        if (!u[i][j])
        {
            ind.clear();
            dfs(i, 0);
            int sz = ind.size();
            map <int, int> cnt;
            for (auto c : ind)
            {
                cnt[d[c].second]++;
            }
            ans = (ans * (ll) fact[sz]) % M;
            for (auto c : cnt)
            {
                ans = (ans * (ll) rfact[c.second]) % M;
            }
        }
    }
    printf("%lld\n", ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:146:19: error: 'j' was not declared in this scope
  146 |         if (!u[i][j])
      |                   ^