题目 › egoi26-foxfamilies

Fox Families

EGOI 2026 · 2026-05 · L3 困难 · C++17 · 时限 2 秒 · 子任务取最低分

查看原题跳到结果

题面

来源:EGOI 2026 官方 PDF。模型收到的是由同一份 Typst 源文件转换的文字。

EGOI 2026 Fox Families 官方题面第 1 页EGOI 2026 Fox Families 官方题面第 2 页

结果

Kimi K3.1 ProKimi

auto(max)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 35.8k平均输出 token(含思考) ↓
  • 23.2输出速度 tokens/s ↑
  • 1682 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 38.9k平均输出 token(含思考) ↓
  • 193.7输出速度 tokens/s ↑
  • 209 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 43.0k平均输出 token(含思考) ↓
  • 153.5输出速度 tokens/s ↑
  • 230 秒延迟 ↓

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

代码

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

struct FoxFamilies {
    struct Item {
        int r, id;
    };

    using LMap = map<int, Item>;
    using It = LMap::iterator;

    struct ExtremeSet {
        LMap byL;
        map<int, int> byR; // r -> l
    };

    // 0: maximal intervals, 1: minimal intervals in their families.
    array<ExtremeSet, 2> ex;

    vector<int> parent, sz;
    vector<array<int, 2>> lo, hi; // Smallest/largest L of each extreme block.

    int find(int x) {
        while (parent[x] != x) {
            parent[x] = parent[parent[x]];
            x = parent[x];
        }
        return x;
    }

    void addNode() {
        int id = (int)parent.size();
        parent.push_back(id);
        sz.push_back(1);
        lo.push_back({-1, -1});
        hi.push_back({-1, -1});
    }

    int unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b) return a;

        if (sz[a] < sz[b]) swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];

        for (int t = 0; t < 2; ++t) {
            if (lo[b][t] == -1) continue;
            if (lo[a][t] == -1) {
                lo[a][t] = lo[b][t];
                hi[a][t] = hi[b][t];
            } else {
                lo[a][t] = min(lo[a][t], lo[b][t]);
                hi[a][t] = max(hi[a][t], hi[b][t]);
            }
        }
        return a;
    }

    // containing=true: old interval contains [l,r].
    // containing=false: old interval is contained in [l,r].
    pair<It, It> getRange(int t, bool containing, int l, int r) {
        auto &s = ex[t];

        if (containing) {
            auto ir = s.byR.lower_bound(r);
            if (ir == s.byR.end()) {
                return {s.byL.end(), s.byL.end()};
            }

            auto begin = s.byL.find(ir->second);
            if (begin == s.byL.end() || begin->first > l) {
                return {s.byL.end(), s.byL.end()};
            }

            auto finish = s.byL.upper_bound(l);
            return {begin, finish};
        } else {
            auto begin = s.byL.lower_bound(l);
            if (begin == s.byL.end() || begin->second.r > r) {
                return {s.byL.end(), s.byL.end()};
            }

            auto ir = s.byR.upper_bound(r);
            It finish = (ir == s.byR.end())
                            ? s.byL.end()
                            : s.byL.find(ir->second);
            return {begin, finish};
        }
    }

    vector<int> queryComponents(int t, bool containing, int l, int r) {
        vector<int> result;
        auto range = getRange(t, containing, l, r);
        auto &s = ex[t];
        auto it = range.first;

        while (it != s.byL.end()) {
            if (it == range.second) break;

            // These checks also handle jumping past range.second.
            if (containing) {
                if (it->first > l) break;
            } else {
                if (it->second.r > r) break;
            }

            int root = find(it->second.id);
            result.push_back(root);

            // Extremes of one family form a contiguous block.
            it = s.byL.upper_bound(hi[root][t]);
        }

        return result;
    }

    It eraseAt(int t, It it) {
        auto &s = ex[t];
        int l = it->first;
        int r = it->second.r;
        int root = find(it->second.id);

        bool hasPrev = (it != s.byL.begin());
        auto prv = hasPrev ? prev(it) : s.byL.end();
        auto nxt = next(it);

        int oldLo = lo[root][t];
        int oldHi = hi[root][t];

        s.byR.erase(r);
        s.byL.erase(it);

        if (oldLo == l || oldHi == l) {
            if (oldLo == oldHi) {
                lo[root][t] = hi[root][t] = -1;
            } else {
                if (oldLo == l) lo[root][t] = nxt->first;
                if (oldHi == l) hi[root][t] = prv->first;
            }
        }

        return nxt;
    }

    void removeRange(int t, bool containing, int l, int r) {
        auto range = getRange(t, containing, l, r);
        auto it = range.first;
        while (it != range.second) {
            it = eraseAt(t, it);
        }
    }

    void addExtreme(int t, int l, int r, int id) {
        ex[t].byL[l] = Item{r, id};
        ex[t].byR[r] = l;

        int root = find(id);
        if (lo[root][t] == -1) {
            lo[root][t] = hi[root][t] = l;
        } else {
            lo[root][t] = min(lo[root][t], l);
            hi[root][t] = max(hi[root][t], l);
        }
    }
};

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

    int N;
    cin >> N;

    FoxFamilies solver;
    long long families = 0;

    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        solver.addNode();

        // Families containing an old interval that contains the new one.
        auto containing = solver.queryComponents(0, true, l, r);

        // Families containing an old interval contained in the new one.
        auto contained = solver.queryComponents(1, false, l, r);

        vector<int> components = containing;
        components.insert(components.end(), contained.begin(), contained.end());
        sort(components.begin(), components.end());
        components.erase(unique(components.begin(), components.end()),
                         components.end());

        // If no old interval contains the new one, it becomes maximal.
        if (containing.empty()) {
            solver.removeRange(0, false, l, r);
        }

        // If it contains no old interval, it becomes minimal.
        if (contained.empty()) {
            solver.removeRange(1, true, l, r);
        }

        int root = i;
        for (int c : components) {
            root = solver.unite(root, c);
        }
        (void)root;

        if (containing.empty()) {
            solver.addExtreme(0, l, r, i);
        }
        if (contained.empty()) {
            solver.addExtreme(1, l, r, i);
        }

        families += 1LL - (long long)components.size();
        cout << families << '\n';
    }

    return 0;
}