fork download
  1. /*
  2.   author : [ Godsent ]
  3.   created : 2025.10.19 12:51:16
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10. #define el '\n'
  11. #define int long long
  12. #define lb lower_bound
  13. #define ub upper_bound
  14. #define fi first
  15. #define se second
  16. #define sz(x) ((int)(x).size())
  17. #define all(v) (v).begin(), (v).end()
  18. #define pb push_back
  19. #define prs(n) fixed << setprecision(n)
  20.  
  21. const int mod = 1e9 + 7;
  22. const int N = 2e5 + 5;
  23. const int INF = 1e18;
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27. template <typename T>
  28. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  29.  
  30. int ask(int x) {
  31. cout << "? " << x << endl;
  32. int ans;
  33. cin >> ans;
  34. return ans;
  35. }
  36.  
  37. int giaithua(int n) {
  38. int ans = 1;
  39. for (int i = 1; i <= n; i++) ans *= i;
  40. return ans;
  41. }
  42.  
  43. void Solve() {
  44. int n;
  45. cin >> n;
  46. map<int, int> mp;
  47. vector<pair<int, int>> q;
  48. for (int i = 1; i <= 6 * n; i += 6) {
  49. int x = ask(i);
  50. mp[x]++;
  51. q.pb({i, x});
  52. }
  53.  
  54. vector<int> ans;
  55. set<int> st = {1, 2, 3, 4, 5, 6};
  56. for (int i = 1; i <= 6; i++) {
  57. if (mp[i] != giaithua(5)) {
  58. ans.pb(i);
  59. st.erase(i);
  60. break;
  61. }
  62. }
  63.  
  64. int k = 0;
  65. for (int i = 0; i < sz(q); i++) {
  66. auto [j, x] = q[i];
  67. if (x == ans[0]) q[k++] = q[i];
  68. }
  69. q.resize(k);
  70.  
  71. mp.clear();
  72. for (int i = 0; i < sz(q); i++) {
  73. int x = ask(q[i].fi + 1);
  74. mp[x]++;
  75. q[i] = {q[i].fi + 1, x};
  76. }
  77.  
  78. for (auto &x : st) {
  79. if (mp[x] != giaithua(4)) {
  80. ans.pb(x);
  81. st.erase(x);
  82. break;
  83. }
  84. }
  85.  
  86. k = 0;
  87. for (int i = 0; i < sz(q); i++) {
  88. auto [j, x] = q[i];
  89. if (x == ans[0]) q[k++] = q[i];
  90. }
  91. q.resize(k);
  92.  
  93. mp.clear();
  94. for (int i = 0; i < sz(q); i++) {
  95. int x = ask(q[i].fi + 1);
  96. mp[x]++;
  97. q[i] = {q[i].fi + 1, x};
  98. }
  99.  
  100. for (auto& x : st) {
  101. if (mp[x] != giaithua(3)) {
  102. ans.pb(x);
  103. st.erase(x);
  104. break;
  105. }
  106. }
  107.  
  108. k = 0;
  109. for (int i = 0; i < sz(q); i++) {
  110. auto [j, x] = q[i];
  111. if (x == ans[0]) q[k++] = q[i];
  112. }
  113. q.resize(k);
  114.  
  115. mp.clear();
  116. for (int i = 0; i < sz(q); i++) {
  117. int x = ask(q[i].fi + 1);
  118. mp[x]++;
  119. q[i] = {q[i].fi + 1, x};
  120. }
  121.  
  122. for (auto& x : st) {
  123. if (mp[x] != giaithua(2)) {
  124. ans.pb(x);
  125. st.erase(x);
  126. break;
  127. }
  128. }
  129.  
  130. k = 0;
  131. for (int i = 0; i < sz(q); i++) {
  132. auto [j, x] = q[i];
  133. if (x == ans[0]) q[k++] = q[i];
  134. }
  135. q.resize(k);
  136.  
  137. mp.clear();
  138. for (int i = 0; i < sz(q); i++) {
  139. int x = ask(q[i].fi + 1);
  140. mp[x]++;
  141. q[i] = {q[i].fi + 1, x};
  142. }
  143.  
  144. for (auto& x : st) {
  145. if (mp[x] != giaithua(1)) {
  146. ans.pb(x);
  147. st.erase(x);
  148. break;
  149. }
  150. }
  151.  
  152. k = 0;
  153. for (int i = 0; i < sz(q); i++) {
  154. auto [j, x] = q[i];
  155. if (x == ans[0]) q[k++] = q[i];
  156. }
  157. q.resize(k);
  158.  
  159. mp.clear();
  160. for (int i = 0; i < sz(q); i++) {
  161. int x = ask(q[i].fi + 1);
  162. mp[x]++;
  163. q[i] = {q[i].fi + 1, x};
  164. }
  165.  
  166. for (auto& x : st) {
  167. if (mp[x] != giaithua(0)) {
  168. ans.pb(x);
  169. st.erase(x);
  170. break;
  171. }
  172. }
  173.  
  174. cout << "! ";
  175. for (auto &x : ans) cout << x << ' ';
  176.  
  177. }
  178.  
  179. signed main() {
  180. ios_base::sync_with_stdio(false);
  181. cin.tie(0);
  182. cout.tie(0);
  183.  
  184. // #ifndef ONLINE_JUDGE
  185. // freopen("test.in", "r", stdin);
  186. // freopen("test.out", "w", stdout);
  187. // #endif
  188.  
  189. int T = 1;
  190. cin>> T;
  191. while (T--) Solve();
  192.  
  193. return 0;
  194. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
! 1 2 3 4 5 6