跳到正文

题解

题解:P17314 [KismetOI 2026 I] oo_vv_oo

tingting28约 9 分钟
原文
文章信息与版本

文章信息

发布
2026年8月25日
收录
2026年8月29日
更新
2026年11月22日
篇幅
约 9 分钟
题目
P17314

版本

  1. v1当前

sub1sub1 显然答案显然为 22,因为只有三个数且另两个数为 00。

显然最大的数肯定大于两边的数,不大于两边的数肯定不是最大的数。

std可以造数据卡到log2nlog_2 n次,但如果引入随机化期望上可以达到log3nlog_3 n次。

实测14次即可。(314=4782969>1063^{14}=4782969>10^6)

复杂度 O(n)O(n)。

代码1
C++
#include <bits/stdc++.h>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;
using f32 = float;
using f64 = double;
using f96 = long double;
using f128 = __float128;

unsigned s = 1;

unsigned r(){
  	s ^= s << 13;
    s ^= s >> 17;
    s ^= s << 5;
    return s;
}

unsigned pre[1000010];
vector<unsigned> vec;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    unsigned n, m;
    cin >> n >> m;
    vec.resize(n - 2);
    for (unsigned i = 0; i < n - 2; ++i) {
        vec[i] = i + 1;
    }
    memset(pre, 0xff, sizeof(pre));
    if (n == 3) {
        cout << "! " << 2 << endl;
        return 0;
    }
    while (vec.size() != 3 && m--) {
        auto p = vec;
        vec.clear();
        vec.push_back(1);
        for (auto &i: p) {
            if (pre[i]) {
                vec.push_back(i);
                pre[i] = 0;
            }
        }
        if (vec.size() == 2) {
            break;
        }
        for (unsigned i = 0; i < vec.size(); ++i) {
            swap(vec[r() % (vec.size() - 1) + 1], vec[r() % (vec.size() - 1) + 1]);
        }
        vec.push_back(n);
        cout << "? " << vec.size() << " ";
        for (unsigned i = 0; i < vec.size(); ++i) {
            cout << vec[i] << " ";
        }
        cout << endl;
        unsigned c, v;
        cin >> c;
        memset(pre, 0, sizeof(pre));
        while (c--) {
            cin >> v;
            pre[vec[v - 1]] = true;
        }
    }
    cout << "! " << vec[r() % (vec.size() - 1) + 1] << endl;
    return 0;
}

需保证 1≤ix≤n1 \le i_x \le n,但可以有相同的。

后面的部分每次减少到原来的 13\frac{1}{3},可上限是 nn,那是不是很浪费?

考虑随机添加一些数,但不能有相同的数相等,因为这样最大的数也不能满足大于两边的数(这样会变成相等,不满足要求)。

实测6次即可,但复杂度退化到了 O(nlogn)O(n log n)。

题目给的20次似乎太宽松了。

代码2
C++
#include <bits/stdc++.h>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using i128 = __int128_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using u128 = __uint128_t;
using f32 = float;
using f64 = double;
using f96 = long double;
using f128 = __float128;

unsigned s = 1;

unsigned r(){
	s ^= s << 13;
    s ^= s >> 17;
    s ^= s << 5;
    return s;
}

unsigned pre[1000010], cnt[1000010];
vector<unsigned> vec;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    unsigned n, m;
    cin >> n >> m;
    vec.resize(n - 2);
    for (unsigned i = 0; i < n - 2; ++i) {
        vec[i] = i + 1;
    }
    memset(pre, 0xff, sizeof(pre));
    if (n == 3) {
        cout << "! " << 2 << endl;
        return 0;
    }
    m = 6;
    while (vec.size() != 3 && m--) {
        auto p = vec;
        vec.clear();
        vec.push_back(1);
        for (auto &i: p) {
            // cout << i << " " << pre[i] << endl;
            if (pre[i]) {
                vec.push_back(i);
                pre[i] = 0;
            }
        }
        if (vec.size() == 2) {
            break;
        }
        for (unsigned i = 0; i < vec.size(); ++i) {
            swap(vec[r() % (vec.size() - 1) + 1], vec[r() % (vec.size() - 1) + 1]);
        }
        unsigned C = vec.size() - 1, K = n - 1;
        for (int i = 0; vec.size() < K; ++i) {
            unsigned v = r() % C + 1;
            while (vec[v] == vec.back()) {
                v = r() % C + 1;
            }
            vec.push_back(vec[v]);
        }
        vec.push_back(n);
        cout << "? " << vec.size() << " ";
        for (unsigned i = 0; i < vec.size(); ++i) {
            cout << vec[i] << " ";
        }
        for (unsigned i = 1; i < vec.size() - 1; ++i) {
            ++cnt[vec[i]];
        }
        cout << endl;
        unsigned c, v;
        cin >> c;
        memset(pre, 0, sizeof(pre));
        while (c--) {
            cin >> v;
            --cnt[vec[v - 1]];
            if (!cnt[vec[v - 1]]) {
                pre[vec[v - 1]] = true;
            }
        }
        // pre[vec[v - 1]] = true;
    }
    cout << "! " << vec[r() % (vec.size() - 1) + 1] << endl;
    return 0;
}
原文