PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000110. Tìm phần tử trong mảng hình núi (Find in Mountain Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tìm phần tử trong mảng hình núi (Find in Mountain Array)

Find in Mountain Array

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A mountain array has at least 33 entries and exactly one peak index kk (0<k<n−10<k<n-1), with a0<a1<⋯<aka_0<a_1<\cdots<a_k and ak>ak+1>⋯>an−1a_k>a_{k+1}>\cdots>a_{n-1}. You know its length nn and target tt but cannot inspect the whole array. Find the smallest index ii with ai=ta_i=t, or −1-1 if absent. Indices start from 00. The original API calls are adapted to interactive queries while retaining the access limit.

Input

Initially, the judge sends nn and tt on one line. Array entries remain hidden. After each query the judge sends the requested array value as an integer.

Output

To read index ii, print ? i with 0≤i<n0\le i<n. The judge returns aia_i. At most 100 queries are allowed; repeated queries to the same index still count. Finish by printing ! ans where ansans is the smallest matching index or -1. Flush each message.

Interactive Protocol

Lines beginning with ? are queries to the judge; lines beginning with ! are final answers. Do not print any other text to standard output.

Subtasks

  • Subtask 1 (20 points): 3≤n≤403\le n\le 40; 0≤t,ai≤1090\le t,a_i\le10^9; 1≤k≤n−21\le k\le n-2; a0<⋯<ak>⋯>an−1a_0<\cdots<a_k>\cdots>a_{n-1}.
  • Subtask 2 (30 points): 3≤n≤10003\le n\le 1000; 0≤t,ai≤1090\le t,a_i\le10^9; 1≤k≤n−21\le k\le n-2; a0<⋯<ak>⋯>an−1a_0<\cdots<a_k>\cdots>a_{n-1}.
  • Subtask 3 (50 points): 3≤n≤100003\le n\le 10000; 0≤t,ai≤1090\le t,a_i\le10^9; 1≤k≤n−21\le k\le n-2; a0<⋯<ak>⋯>an−1a_0<\cdots<a_k>\cdots>a_{n-1}.

Examples

Input

7 3

Output

? 3
? 4
? 5
? 2
! 2

This is an illustrative transcript, not a fixed output file. Hidden values are revealed only in the explanation to make the example understandable.

Explanation

Suppose the hidden array is [1,2,3,4,5,3,1][1,2,3,4,5,3,1] and t=3t=3. Queries at indices 3,4,5,23,4,5,2 return 4,5,3,34,5,3,3. The target occurs at 22 and 55, so the smallest index is 22; output ! 2. Other query orders are allowed.