Untitled

sol.cpp
mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.6 kB
4
Indexable
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <unordered_set>

using namespace std;

int n, sum, res;
bool in[1000];
vector<int>v, ans;

int find(int x, int k) {
    int l = 1, r = n, mid;
    while (l <= r) {
        mid = (l + r) >> 1, sum++;
        cout << "? " << x << " " << k << " " << mid - l + 1 << " ";
        for (int i = l; i <= mid; i++)
            cout << i << " ";
        cout << endl;
        cout.flush();
        cin >> res;
        if (!res) l = mid + 1;
        else r = mid - 1;
    }
    return l;
}

bool query_v(int x, int k) {
    cout << "? " << x << " " << k << " " << v.size() << " ";
    for (int j = 0; j < v.size(); j++)
        cout << v[j] << " ";
    cout << endl;
    cout.flush();
    cin >> res;
    return res;

}

void update(int k) {
    for (int i = 1; i <= n; i++) {
        if (in[i]) continue;
        else if (query_v(i, k) == 1) in[i] = 1, v.push_back(i);
    }
}

int main(int argc, char** argv) {

    cin >> n;
    int p = find(1, n);
    in[p] = 1, v.push_back(p);
    for (int i = 1; i <= 62; i++) {
        int p2 = find(p, i);
        if (!in[p2]) in[p2] = 1, v.push_back(p2);
    }
    for (int i = 1; i <= 4; i *= 2) {
        int cur = v.size();
        update(i * 63);
        if (v.size() - cur < i * 63) break;
    }
    for (int i = 1; i <= n; i++)
        if (in[i]) ans.push_back(i);
        else if (query_v(i, n)) ans.push_back(i);
    cout << "! " << ans.size() << " ";
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}