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

#GL0000399. Khôi phục cấp số cộng bí mật (Recover the Hidden Arithmetic Progression)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Khôi phục cấp số cộng bí mật (Recover the Hidden Arithmetic Progression)

Recover the Hidden Arithmetic Progression

Source: Codeforces

Version: Phuoc Hung OJ Extended

Mode: interactive.

Problem Statement

A hidden array a1,…,ana_1,\ldots,a_n is a permutation of a strictly increasing integer arithmetic progression bi=b1+(i−1)db_i=b_1+(i-1)d with d>0d>0. All elements are integers between 0 and 10910^9.

Determine the minimum element b1b_1 and the common difference dd using at most 60 queries:

  • ? i, 1≤i≤n1\le i\le n: receive the value aia_i.
  • > x, 0≤x≤1090\le x\le10^9: receive 1 if some hidden value exceeds xx, otherwise 0.

Output ! b_1 d and terminate. This final answer is not a query. Flush after each question. Stop immediately upon receiving -1.

PHOJ hidden test format

Each .in holds nn followed by its nn hidden values. The judge sends only nn initially; the rest can only be obtained through legal queries. One interaction per file.

Subtasks

  • Subtask 1 (20 points): 2≤n≤602\le n\le60, 0≤ai≤1090\le a_i\le10^9, positive integer difference; 60-query limit.
  • Subtask 2 (30 points): 2≤n≤5 0002\le n\le5\,000, 0≤ai≤1090\le a_i\le10^9, positive integer difference; 60-query limit.
  • Subtask 3 (50 points): 2≤n≤1062\le n\le10^6, 0≤ai≤1090\le a_i\le10^9, positive integer difference; 60-query limit.

Example interaction

Judge: 4
Player: ? 1
Judge: 14
Player: ? 2
Judge: 24
Player: ? 3
Judge: 9
Player: ? 4
Judge: 19
Player: ! 9 5

Explanation: Sorted values are [9,14,19,24][9,14,19,24], whose smallest value is 9 and constant difference is 5.