#GL0000390. Truy vấn GCD (GCD Queries)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn GCD (GCD Queries)
GCD Queries
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
The jury fixes a hidden permutation of . Find two indices (possibly equal) such that or . You may issue no more than GCD queries.
This is a real interactive problem; output is not compared to one predetermined file.
Interactive protocol
- First read .
- Print
? i j, flush, then read . Both indices must be in and distinct. - Print
! x yto answer, flush, and read verdict1or-1. Terminate immediately on-1. - The permutation does not change during the interaction; the query limit is .
For the PHOJ interactor, each hidden test file stores followed by a permutation . Only is revealed to the contestant. Each file represents one independent session rather than multiple interactive cases.
Subtasks
-
Subtask 1 (20 points): ; is a permutation of ; at most queries.
-
Subtask 2 (30 points): ; is a permutation of ; at most queries.
-
Subtask 3 (50 points): ; is a permutation of ; at most queries.
Example interaction
Suppose the hidden permutation is :
Jury: 3
Player: ? 1 3
Jury: 1
Player: ? 2 3
Jury: 2
Player: ! 3 2
Jury: 1
The replies are and . Index contains zero, so the final pair is accepted. This is a transcript illustration, not unique expected output.