/* -*- coding: utf-8 -*- * * 2165.cc: No.2165 Let's Play Nim! - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 75000; const int BN = 17; enum { First = 1, Second = 0 }; /* typedef */ typedef pair pii; typedef set spii; /* global variables */ int as[MAX_N]; spii bps[BN]; /* subroutines */ inline int msb(int x) { int k = 0, bk = 1; while ((bk << 1) <= x) k++, bk <<= 1; //printf("msb(%d)=%d\n", x, k); return k; } void replace(int i, int ai) { bps[msb(as[i])].erase(pii(as[i], i)); if (ai > 0) bps[msb(ai)].insert(pii(ai, i)); as[i] = ai; } int my_act(int x) { int i = bps[msb(x)].begin()->second; int ai = x ^ as[i], k = as[i] - ai; replace(i, ai); printf("%d %d\n", i + 1, k); fflush(stdout); int r; scanf("%d", &r); return r; } int judge_act() { int i, k, r; scanf("%d%d%d", &i, &k, &r), i--; int ai = as[i] - k, x = as[i] ^ ai; replace(i, ai); return (r < 0) ? -1 : x; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); int x = 0; for (int i = 0; i < n; i++) { x ^= as[i]; bps[msb(as[i])].insert(pii(as[i], i)); } if (x != 0) { printf("%d\n", First), fflush(stdout); my_act(x); } else printf("%d\n", Second), fflush(stdout); for (;;) { int x = judge_act(); if (x < 0) break; int r = my_act(x); if (r < 0) break; } return 0; }