题目 › usaco-1502

True or False Test

USACO 2025 February · 铂金组 · 2025-02 · L4 顶尖 · C++17 · 时限 3 秒 · 测试点等分

查看原题跳到结果

题面

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

**Note: The time limit for this problem is 3s, 1.5x the default. The memory limit for this problem is 512MB, twice the default.**

Bessie is taking an $N$-question true or false test ($1\le N\le 2\cdot 10^5$). For the $i$-th question, she will gain $a_i$ points if she gets it correct, lose $b_i$ points if she gets it incorrect, or remain even if she does not answer it ($0<a_i,b_i\le 10^9$).

Bessie knows all the answers because she is a smart cow, but worries that Elsie (who is administering the test) will retroactively change up to $k$ of the questions after the test such that Bessie does not get those questions correct.

Given $Q$ ($1\le Q\le N+1$) candidate values of $k$ ($0\le k\le N$), determine the number of points Bessie can guarantee for each $k$, given that she must answer at least $k$ questions.

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

The first line contains $N$ and $Q$.

The next $N$ lines each contain $a_i$ and $b_i$.

The next $Q$ lines each contain a value of $k$. No value of $k$ appears more than once.

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

The answer for each $k$ on a separate line.

SAMPLE INPUT:

2 3
3 1
4 2
2
1
0

SAMPLE OUTPUT:

-3
1
7

For each value of $k$, it is optimal for Bessie to answer all of the questions.

SCORING:

  • Inputs 2-4: $N\le 100$
  • Inputs 5-7: $Q\le 10$, $N\le 2\cdot 10^5$
  • Inputs 7-20: No additional constraints.

Problem credits: Benjamin Qi

结果

Kimi K3.1 ProKimi

max

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 11.8k平均输出 token(含思考) ↓
  • 26.8输出速度 tokens/s ↑
  • 464 秒延迟 ↓
  • 0.34×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

Kimi K3.1 Pro(high)Kimi high

high

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 11.8k平均输出 token(含思考) ↓
  • 26.8输出速度 tokens/s ↑
  • 464 秒延迟 ↓
  • 0.34×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

3/3

解出的采样 ↑

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

MiniMax M3.1 FlashMiniMax

auto(max)

3/3

解出的采样 ↑

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

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

代码

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

using ll = long long;

struct Node {
    int l = 0, r = 0, cnt = 0;
    ll sum = 0;
};

int N, M;
vector<ll> bValues;
vector<Node> seg;

int update(int prev, int lo, int hi, int pos, ll value) {
    int cur = (int)seg.size();
    seg.push_back(seg[prev]);
    seg[cur].cnt++;
    seg[cur].sum += value;

    if (lo < hi) {
        int mid = (lo + hi) >> 1;
        if (pos <= mid) {
            seg[cur].l = update(seg[prev].l, lo, mid, pos, value);
        } else {
            seg[cur].r = update(seg[prev].r, mid + 1, hi, pos, value);
        }
    }
    return cur;
}

ll querySumOfKSmallest(int node, int k) {
    ll result = 0;
    int lo = 1, hi = M;

    while (lo < hi) {
        int mid = (lo + hi) >> 1;
        int left = seg[node].l;
        int leftCount = seg[left].cnt;

        if (k <= leftCount) {
            node = left;
            hi = mid;
        } else {
            result += seg[left].sum;
            k -= leftCount;
            node = seg[node].r;
            lo = mid + 1;
        }
    }

    result += 1LL * k * bValues[lo - 1];
    return result;
}

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

    int Q;
    cin >> N >> Q;

    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }

    vector<int> queries(Q);
    for (int &k : queries) {
        cin >> k;
    }

    vector<int> order(N);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int i, int j) {
        return a[i] + b[i] > a[j] + b[j];
    });

    bValues = b;
    sort(bValues.begin(), bValues.end());
    bValues.erase(unique(bValues.begin(), bValues.end()), bValues.end());
    M = (int)bValues.size();

    seg.reserve((size_t)N * 20 + 5);
    seg.push_back(Node());

    vector<int> roots(N + 1, 0);
    vector<ll> prefixA(N + 1, 0), prefixB(N + 1, 0);

    for (int r = 1; r <= N; r++) {
        int id = order[r - 1];
        int pos = (int)(lower_bound(bValues.begin(), bValues.end(), b[id])
                        - bValues.begin()) + 1;
        roots[r] = update(roots[r - 1], 1, M, pos, b[id]);
        prefixA[r] = prefixA[r - 1] + a[id];
        prefixB[r] = prefixB[r - 1] + b[id];
    }

    vector<ll> suffixA(N + 1);
    for (int r = 0; r <= N; r++) {
        suffixA[r] = prefixA[N] - prefixA[r];
    }

    vector<ll> answer(N + 1, 0);

    function<void(int, int, int, int)> solve =
        [&](int l, int r, int optL, int optR) {
            if (l > r) return;

            int mid = (l + r) >> 1;
            int start = max(mid, optL);
            int bestPos = start;
            ll bestValue = numeric_limits<ll>::min();

            for (int pos = start; pos <= optR; pos++) {
                ll penalty;
                if (mid == 0) {
                    penalty = 0;
                } else if (mid == pos) {
                    penalty = prefixB[pos];
                } else {
                    penalty = querySumOfKSmallest(roots[pos], mid);
                }

                ll value = suffixA[pos] - penalty;
                if (value > bestValue) {
                    bestValue = value;
                    bestPos = pos;
                }
            }

            answer[mid] = bestValue;

            if (l < mid) {
                solve(l, mid - 1, optL, bestPos);
            }
            if (mid < r) {
                solve(mid + 1, r, bestPos, optR);
            }
        };

    solve(0, N, 0, N);

    for (int k : queries) {
        cout << answer[k] << '\n';
    }

    return 0;
}