1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include <bits/stdc++.h> using namespace std; const int N = 5e2 + 5; typedef vector<int> vint; int n; void Reduce(vector<int> &S) { sort(S.begin(),S.end()); S.erase(unique(S.begin(),S.end()),S.end()); }
bool Ask(int u,int k,const vector<int> &S) { printf("? %d %d %d ",u,k,(int)S.size()); for(auto i : S) printf("%d ",i); printf("\n"); fflush(stdout); int res; cin >> res; return res; } bool Ask(int u,int k,int l,int r) { vector<int> S; for(int i = l;i <= r;i++) S.push_back(i); return Ask(u,k,S); } inline int Getnxt(int u,int k) { if(k == 0) return u; int lef = 1,rig = n; while(lef < rig) { int mid = lef + rig >> 1; if(Ask(u,k,1,mid)) rig = mid; else lef = mid + 1; } return lef; } inline int GetLen(int st) { vector<int> st8; for(int i = 0;i <= 7;i++) st8.push_back(Getnxt(st,i)); Reduce(st8); for(int i = 1;i * 8 <= n;i++) if(Ask(st,i * 8,st8)) return i * 8; return n; } vector<int> C; bool inc[N]; void addc(int x) { if(inc[x]) return;inc[x] = true;C.push_back(x);} int main() { cin >> n; int st = Getnxt(1,n + 1); int len = GetLen(st); for(int i = 0;i * 4 <= len + 4;i++) addc(Getnxt(st,i * 4)); for(int i = 1;i <= n;i++) if(!inc[i] && Ask(i,2,C)) addc(i); for(int i = 1;i <= n;i++) if(!inc[i] && Ask(i,1,C)) addc(i); vector<int> Ans; for(int i = 1;i <= n;i++) if(inc[i]) Ans.push_back(i); else if(Ask(i,n + 1,C)) Ans.push_back(i); printf("! %d ",(int)Ans.size()); for(auto i : Ans) printf("%d ",i); printf("\n"); fflush(stdout); return 0; }
|