Advertisement
Galebickosikasa

Untitled

Nov 21st, 2020 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  2. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
  3. // #pragma comment(linker, "/stack:200000000"]
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <unordered_set>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <bitset>
  16. #include <stack>
  17. #include <random>
  18. #include <fstream>
  19. #include <sstream>
  20. #include <chrono>
  21.  
  22. #define fi first
  23. #define se second
  24. #define pb push_back
  25. #define ll long long
  26. #define ld long double
  27. #define hm unordered_map
  28. #define pii pair<int, int>
  29. #define sz(a) (int)a.size()
  30. #define all(a) a.begin(), a.end()
  31. #define cinv(v) for (auto& x: v) cin >> x
  32. #define fr(i, n) for (int i = 0; i < n; ++i)
  33. #define fl(i, l, n) for (int i = l; i < n; ++i)
  34.  
  35. // #define int ll
  36.  
  37. template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
  38. template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
  39.  
  40. using namespace std;
  41.  
  42. #ifdef LOCAL
  43. #define dbg(x) cerr << #x << " : " << x << '\n'
  44. const int maxn = 20;
  45. #else
  46. #define dbg(x)
  47. const int maxn = 2e5 + 20;
  48. #endif
  49.  
  50. //tg: @galebickosikasa
  51.  
  52. ostream& operator << (ostream& out, vector<int>& v) {
  53. for (auto& x: v) out << x << ' ';
  54. return out;
  55. }
  56.  
  57. ostream& operator << (ostream& out, pii& v) {
  58. out << v.fi << ", " << v.se;
  59. return out;
  60. }
  61.  
  62. istream& operator >> (istream& in, pii& a) {
  63. in >> a.fi >> a.se;
  64. return in;
  65. }
  66.  
  67. const ll inf = (ll) 2e9;
  68. const ld pi = asin (1) * 2;
  69. const ld eps = 1e-8;
  70. const ll mod = (ll)1e9 + 7;
  71. const ll ns = 97;
  72.  
  73. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  74.  
  75.  
  76. int askxor (int i, int j) {
  77. cout << "XOR " << i + 1 << ' ' << j + 1 << endl;
  78. int x;
  79. cin >> x;
  80. return x;
  81. }
  82.  
  83. int askor (int i, int j) {
  84. cout << "OR " << i + 1 << ' ' << j + 1 << endl;
  85. int x;
  86. cin >> x;
  87. return x;
  88. }
  89.  
  90. int askand (int i, int j) {
  91. cout << "AND " << i + 1 << ' ' << j + 1 << endl;
  92. int x;
  93. cin >> x;
  94. return x;
  95. }
  96.  
  97. void solve () {
  98. int n;
  99. cin >> n;
  100. vector<int> goo (n);
  101. map <int, int> kek;
  102. int a = -1, b = -1;
  103. fl (i, 1, n) {
  104. int x = askxor (0, i);
  105. if (kek.count (x)) {
  106. a = kek[x], b = i;
  107. }
  108. kek[x] = i;
  109. goo[i] = x;
  110. if (x == 0) {
  111. a = 0, b = i;
  112. }
  113. }
  114. vector<int> ans (n);
  115. if (a != -1) {
  116. int x = askor (a, b);
  117. goo[0] = goo[a] ^ x;
  118. fl (i, 1, n) ans[i] = goo[0] ^ goo[i];
  119. } else {
  120. int j = -1;
  121. fl (i, 1, n) if (goo[i] == 1) j = i;
  122. int x = askand (0, j);
  123. goo[0] = x;
  124. fl (i, 1, n) {
  125. if (i == j || goo[i] & 1) continue;
  126. int y = askor (0, i);
  127. if (y & 1) ++goo[0];
  128. }
  129. fl (i, 1, n) ans[i] = goo[0] ^ goo[i];
  130. }
  131. cout << "! " << ans << endl;
  132.  
  133.  
  134.  
  135.  
  136. }
  137.  
  138. signed main () {
  139. ios_base::sync_with_stdio(false);
  140. cin.tie(nullptr);
  141. cout.tie(nullptr);
  142. int q = 1;
  143. // cin >> q;
  144. while (q--) solve ();
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. }
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement