luogu#P14982. [USACO26JAN1] Supervision G

    ID: 15063 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP线段树USACO2026双指针 two-pointer

[USACO26JAN1] Supervision G

Problem Description

There are NN (1N1061\le N \leq 10^6) cows in cow camp, labeled 1N1\dots N. Each cow is either a camper or a coach.

A nonempty subset of the cows will be selected to attend a field trip. If the iith cow is selected, the cow will move to position pip_i (0pi1090\le p_i \leq 10^9) on a number line, where the array pp is strictly increasing.

A nonempty subset of the cows is called "good" if for every selected camper, there is a selected coach within DD units to the left, inclusive (0D1090\le D\le 10^9). How many good subsets are there, modulo 109+710^9+7?

Input Format

The first line contains two integers NN and DD.

The next NN lines each contain two integers pip_i and oio_i. pip_i denotes the position the iith cow will move to. oi=1o_i=1 means the iith cow is a coach, whereas oi=0o_i=0 means the iith cow is a camper.

It is guaranteed that the pip_i are given in strictly increasing order.

Output Format

Output the number of good subsets modulo 109+710^9 + 7.

6 1
3 1
4 0
6 1
7 1
9 0
10 0
11
20 24
3 0
14 0
17 1
20 0
21 0
22 1
28 0
30 0
32 0
33 1
38 0
40 0
52 0
58 0
73 0
75 0
77 1
81 1
84 1
97 0
13094

Hint

The last two campers can never be selected. All other nonempty subsets work as long as if cow 22 is selected, then cow 11 is also selected.


  • Input 3: N=20N=20
  • Input 4: D=0D=0
  • Inputs 5-8: N5000N\le 5000
  • Inputs 9-16: No additional constraints.