QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200926 | #7510. Independent Set | w4p3r | ML | 1ms | 3544kb | C++20 | 2.2kb | 2023-10-05 01:13:25 | 2023-10-05 01:13:26 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define FOR(i, a, b) for(int i = a; i <= b; i ++)
#define REP(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define fr first
#define sd second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
char ch = getchar();
ll s = 0, w = 1;
while (ch < '0' || ch > '9') {if (ch == '-')w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {s = s * 10 + ch - '0'; ch = getchar();}
return s * w;
}
#define N 4010
int n, m;
int S = 0, cnt[N << 2][N];
bool vst[N];
vector<pair<int, int>>ans;
vector<int> ask(vector<int>a)
{
if (a.empty())return {};
S += a.size(); assert(S <= 176000);
cout << "? " << a.size() << ' ';
for (int x : a)cout << x << ' '; cout << endl;
vector<int>b;
for (int x : a) {int t; cin >> t; b.push_back(t);}
return b;
}
void calc(const vector<int>a, int l, int r, int tx, vector<int>b)
{
if (l == r)
{
for (int x : b){while (cnt[tx][x] --)ans.push_back({a[l], x});}
return ;
}
vector<int>tmp;
int mid = (l + r) >> 1;
FOR(i, l, mid)tmp.push_back(a[i]);
for (int x : b)tmp.push_back(x);
vector<int>ans = ask(tmp);
int m = b.size();
vector<int>lb, rb;
FOR(i, 0, m - 1)
{
cnt[tx << 1][b[i]] = ans[i + (mid - l + 1)];
cnt[tx << 1 | 1][b[i]] = cnt[tx][b[i]] - ans[i + (mid - l + 1)];
if(cnt[tx << 1][b[i]])lb.push_back(b[i]);
if(cnt[tx << 1 | 1][b[i]])rb.push_back(b[i]);
}
calc(a, l, mid, (tx << 1), lb); calc(a, mid + 1, r, (tx << 1 | 1), rb);
}
void sol(vector<int>c)
{
if (c.empty())return ;
vector<int>tc = c;
for (int x : c)tc.push_back(x), vst[x] = 0;;
vector<int>tmp = ask(tc);
vector<int>X, Y;
int m = c.size();
FOR(i, 0, m - 1)if (!tmp[i])X.push_back(c[i]); else Y.push_back(c[i]), cnt[1][c[i]] = tmp[i + m];
int k = X.size();
calc(X, 0, k - 1, 1, Y);
sol(Y);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
FOR(i, 1, n)
{
vector<int>t = ask({i, i});
while (t[1] --)ans.push_back({i, i});
}
vector<int>a(n);
FOR(i, 0, n - 1)a[i] = i + 1;
sol(a);
cout << "!" << ' ';
cout << ans.size() << ' ';
for (auto [x, y] : ans)cout << x << ' ' << y << ' '; cout << endl;
return 0;
}
/*
6
4 6 8 9 2 4
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3544kb
input:
4 0 0 0 0 0 0 0 1 0 2 1 0 0 2 1 1 0 2 1 0 0 0 0 0
output:
? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ? 8 1 2 3 4 1 2 3 4 ? 3 1 2 3 ? 4 2 3 2 3 ? 1 2 ! 4 4 4 1 2 1 2 1 3
result:
ok Ok, Accepted!
Test #2:
score: -100
Memory Limit Exceeded
input:
4000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ? 2 5 5 ? 2 6 6 ? 2 7 7 ? 2 8 8 ? 2 9 9 ? 2 10 10 ? 2 11 11 ? 2 12 12 ? 2 13 13 ? 2 14 14 ? 2 15 15 ? 2 16 16 ? 2 17 17 ? 2 18 18 ? 2 19 19 ? 2 20 20 ? 2 21 21 ? 2 22 22 ? 2 23 23 ? 2 24 24 ? 2 25 25 ? 2 26 26 ? 2 27 27 ? 2 28 28 ? 2 29 29 ...