题目 › usaco-1547

Supervision

USACO 2026 First · 金组 · 2026-01 · L3 困难 · C++17 · 时限 2 秒 · 测试点等分

查看原题跳到结果

题面

来源:USACO 官网。模型收到的是同一份题面的文字。

There are $N$ ($1\le N \leq 10^6$) cows in cow camp, labeled $1\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 $i$th cow is selected, the cow will move to position $p_i$ ($0\le p_i \leq 10^9$) on a number line, where the array $p$ is strictly increasing.

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

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains two integers $N$ and $D$.

The next $N$ lines each contain two integers $p_i$ and $o_i$. $p_i$ denotes the position the $i$th cow will move to. $o_i=1$ means the $i$th cow is a coach, whereas $o_i=0$ means the $i$th cow is a camper.

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

OUTPUT FORMAT (print output to the terminal / stdout):

Output the number of good subsets modulo $10^9 + 7$.

SAMPLE INPUT:

6 1
3 1
4 0
6 1
7 1
9 0
10 0

SAMPLE OUTPUT:

11

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

SAMPLE INPUT:

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

SAMPLE OUTPUT:

13094

SCORING:

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

Problem credits: Agastya Goel, Eva Zhu, and Benjamin Qi

结果

Kimi K3.1 ProKimi

auto(max)

2/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 93.8采样 2 · 答案错误
  • 100采样 3 · 解出
  • 4.6k平均输出 token(含思考) ↓
  • 23.3输出速度 tokens/s ↑
  • 195 秒延迟 ↓
  • 0.92×CPU 时间 / 官方解 ↓
  • 同阶 2时间复杂度(相对官方解)

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 14.3k平均输出 token(含思考) ↓
  • 191.1输出速度 tokens/s ↑
  • 73 秒延迟 ↓
  • 0.24×CPU 时间 / 官方解 ↓
  • 更优 2、同阶 1时间复杂度(相对官方解)

MiniMax M3.1 FlashMiniMax

auto(max)

2/3

解出的采样 ↑

  • 0.0采样 1 · 编译错误
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 18.8k平均输出 token(含思考) ↓
  • 155.4输出速度 tokens/s ↑
  • 116 秒延迟 ↓
  • 0.29×CPU 时间 / 官方解 ↓
  • 更优 2时间复杂度(相对官方解)

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 58 行
#include <bits/stdc++.h>
using namespace std;

static const long long MOD = 1000000007LL;
static const long long INV2 = 500000004LL;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    long long D;
    cin >> N >> D;

    vector<int> qPos(N), qVal(N);
    int head = 0, tail = 0;

    long long total = 0;   // Sum of all DP states.
    long long active = 0;  // Sum of states whose last coach is still in the queue.
    long long mul = 1;     // Common multiplier for queued values.
    long long invMul = 1;

    for (int i = 0; i < N; ++i) {
        long long p;
        int type;
        cin >> p >> type;

        if (type == 1) {
            // Select this coach after any previous state, or start with it alone.
            long long value = (total + 1) % MOD;
            total = (total + value) % MOD;
            active = (active + value) % MOD;

            qPos[tail] = static_cast<int>(p);
            qVal[tail] = static_cast<int>(value * invMul % MOD);
            ++tail;
        } else {
            long long leftLimit = p - D;

            // These coaches are too far left for this and all future campers.
            while (head < tail && static_cast<long long>(qPos[head]) < leftLimit) {
                long long value = static_cast<long long>(qVal[head]) * mul % MOD;
                active -= value;
                if (active < 0) active += MOD;
                ++head;
            }

            // Every active state may either include or exclude this camper.
            total = (total + active) % MOD;
            active = active * 2 % MOD;
            mul = mul * 2 % MOD;
            invMul = invMul * INV2 % MOD;
        }
    }

    cout << total << '\n';
    return 0;
}