#include #include int n, k, minsteps, x; int GetForTwo(int i, int j) { int t = 1, t2 = j - i; while (t < t2) { t2 -= t; t++; } return t; } int GetSteps(int i, int j, int e, int steps) { int t, min = 1000, p, a, b; if ((e == 1) || (i == j)) return j - i + steps; if (e == 2) { t = GetForTwo(i, j); return steps + t; } t = 2; while (1) { p = (j - i) / t; a = GetSteps(i, i+p, e-1, steps+1); b = GetSteps(i+p+1, j, e, steps+1); if (a < b) a = b; if (min > a) min = a; else break; t++; if (t > 5) break; } return min; } int main() { char c[10] = ""; int i, j, t, p, a, b; scanf("%d%d", &n, &k); i = 1; j = n; gets(c); while (c[0] != 'e') { if (c[0] == 's') i = x + 1; if (c[0] == 'b') { j = x; k--; } if (i != j) { if (k == 1) x = i; else if (k == 2) { t = GetForTwo(i, j); x = i + t - 1; } else { minsteps = 1000; t = 2; while (1) { p = (j - i) / t; a = GetSteps(i, i+p, k-1, 1); b = GetSteps(i+p+1, j, k, 1); if (a < b) a = b; if (minsteps > a) minsteps = a; else break; x = i + p; t++; } } } if (i == j) printf("answer %d\n", i); else printf("query %d\n", x); fflush(stdout); gets(c); } return 0; }