Language: C++

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 200010;
const int mod = 1e9 + 7;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> b, cb[N];
vector<int> t[N];
int n, x, y, lc[N], col[N], ls[N], tc[N], w[N];

#define bi b[i].second

int find_(vector<pii> &a, int k)
{
	int l = 0, r = a.size() - 1;
	while (l != r) {
		int mid = (l + r) >> 1;
		if (a[mid].first <= k) l = mid + 1;
		else r = mid;
	}
	if (a[l] > k) return l - 1;
	else return l;
}

int f[N], st[N];
int f_f(int x) { return x == f[x] ? x : f[x] = f_f(f[x]);} 

void merge(int x1, int x2)
{
	int f1 = f_f(x1), f2 = f_f(x2);
	if (f1 != f2) f[f1] = f2;
}

LL p[N];
LL qpow(LL a, LL b)
{
	LL ret = 1, base = a;
	while (b) {
		if (b & 1) ret = ret * base % mod;
		base = base * base % mod, b >>= 1;
	}
	return ret;
}
LL C(int a, int b) {return p[a] * qpow(p[b], mod - 2) % mod * qpow(p[a - b], mod - 2) % mod;}

int main()
{
	scanf("%d%d%d", &n, &x, &y);
	Rep(i, n){
		scanf("%d%d", &col[i], &w[i]);
		b.push_back(mp(w[i], i));
		cb[col[i]].push_back(mp(w[i], i));	
		f[i] = i;
	}
	sort(b.begin(), b.end());
	Rep(i, n) sort(cb[i].begin(), cb[i].end());
	
	memset(tc, -1, sizeof(tc));
	memset(lc, -1, sizeof(lc));
	memset(ls, -1, sizeof(ls));
	tc[col[b[0].second]] = 0;
	
	Rep(i, n - 1){
		if (col[bi] == col[b[i - 1].second]) lc[i] = lc[i - 1]; 
		else lc[i] = i - 1;
		ls[i] = tc[col[bi]], tc[col[bi]] = i;
		int tmp1 = ls[i], tmp2 = lc[i];
		if (tmp1 != -1){
			if (b[i].first + b[tmp1].first <= x) merge(bi, b[tmp1].second);
			else {
				int tmp = find_(cb[col[bi]], x - b[i].first);
				if (tmp >= 0 && tmp < cb[col[bi]].size()) merge(bi, cb[col[bi]][tmp].second);
			}
		}
		if (tmp2 != -1){
			if (b[i].first + b[tmp2].first <= y){merge(bi, b[tmp2].second);}
			else {
				int tmp = find_(b, y - b[i].first);
				if (tmp >= 0 && tmp < b.size()) merge(bi, b[tmp].second);
			}
		}
	}
	
	Rep(i, n) t[f_f(i)].push_back(col[i]);
	p[0] = 1;
	Rep(i, n) p[i] = p[i - 1] * i % mod;
	
	LL ans = 1;
	
	Rep(i, n) if (t[i].size()) {
		sort(t[i].begin(), t[i].end());	
		int top = 0, cnt = 0;
		for (int j = 0; j < t[i].size(); j ++){
			if (t[i][j] != t[i][j - 1] && j != 0) st[++ top] = cnt, cnt = 0;
			cnt ++;
		}
		int tmp = cnt;
		LL tans = 1;
		while (top){
			tans = tans * C(tmp + st[top], st[top]) % mod;
			tmp += st[top], top --;
		}
		ans = ans * tans % mod;
	}
	printf("%lld\n", ans);
	
	return 0;
}


Compiler output:
a.cc: In function 'int find_(std::vector<std::pair<int, int> >&, int)':
a.cc:32:18: error: no match for 'operator>' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   32 |         if (a[l] > k) return l - 1;
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_pair.h:1058:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1058 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1058:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
/usr/include/c++/14/bits/stl_iterator.h:507:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  507 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1714 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} is not derived from 'const std::move_iterator<_IteratorL>'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1774 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} is not derived from 'const std::move_iterator<_IteratorL>'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_vector.h:2102:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator>(const vector<_Tp, _Alloc>&, const vector<_Tp, _Alloc>&)'
 2102 |     operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:2102:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} is not derived from 'const std::vector<_Tp, _Alloc>'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/vector:87:
/usr/include/c++/14/tuple:2619:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator>(const tuple<_UTypes ...>&, const tuple<_Elements ...>&)'
 2619 |     operator>(const tuple<_TElements...>& __t,
      |     ^~~~~~~~
/usr/include/c++/14/tuple:2619:5: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} is not derived from 'const std::tuple<_UTypes ...>'
   32 |         if (a[l] > k) return l - 1;
      |                    ^
a.cc:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^