QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200931#7510. Independent Setw4p3rTL 0ms0kbC++202.2kb2023-10-05 01:17:162023-10-05 01:17:17

Judging History

你现在查看的是最新测评结果

  • [2023-10-05 01:17:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-05 01:17:16]
  • 提交

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;
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, vector<int>b, vector<int>cnt)
{
	if (l == r)
	{
		int m = b.size();
		FOR(i, 0, m - 1) {while (cnt[i] --)ans.push_back({a[l], b[i]});}
		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, lcnt, rb, rcnt;
	FOR(i, 0, m - 1)
	{
		int vl = tmp[i + (mid - l + 1)], vr = cnt[i] - vl;
		if (vl) {lcnt.push_back(vl); lb.push_back(b[i]);}
		if (vr) {rcnt.push_back(vr); rb.push_back(b[i]);}
	}
	calc(a, l, mid, lb, lcnt); calc(a, mid + 1, r, rb, rcnt);
}
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, cnt;
	int m = c.size();
	FOR(i, 0, m - 1)if (!tmp[i])X.push_back(c[i]); else Y.push_back(c[i]), cnt.push_back(tmp[i + m]);
	int k = X.size();
	calc(X, 0, k - 1, Y, cnt);
	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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

4
0 0
0 0
0 0
0 1
0 2 1 0 0 2 1 1
0 2 1

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 

result: