Yet Another Contest 4 P6 - No More Solitaire

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 8.0s
Memory limit: 256M

Author:
Problem types

Mike has gotten so bored of playing Factor Solitaire that he vows to never play it again! Instead, he has developed an interest in a new game which he calls Factor Klondike.

Josh has a permutation of the first N positive integers p1,p2,,pN, which he keeps hidden from Mike. The goal of the game is to guess Josh's permutation by making as few queries as possible. In one query, Mike selects integers l,r,x such that 1lrN and 1xN, and Josh tells him whether any of the elements pl,pl+1,pl+2,,pr contain x as a factor.

Can you help Mike to win as efficiently as possible? You can make at most 4×105 queries.

Constraints

2N104

p1,p2,,pN is a permutation of the integers 1,2,,N.

Scoring

Let Q be the maximum number of queries made by your program in any test case. Your program will receive the following score:

QScore
0Q1.35×105100
1.35×105<Q1.45×10590
1.45×105<Q1.55×10580
1.55×105<Q1.65×10570
1.65×105<Q1.8×10560
1.8×105<Q2×10550
2×105<Q2.2×10540
2.2×105<Q2.5×10530
2.5×105<Q3×10520
3×105<Q4×10510
Q>4×1050

If your program fails to guess the permutation in any test case, then you will receive 0 points.

Interaction

This is an interactive problem. Note that the interactor is not adaptive, and the target permutation p1,p2,,pN is generated uniformly at random.

At first, you should read in a single integer on a single line, representing the value of N.

Then, you will have the opportunity to make up to 4×105 queries. To make a query, output a line in the form ? l r x. Then, you should read in a single integer on a single line. This integer will be 1 if any of pl,pl+1,pl+2,,pr contain x as a factor, and 0 otherwise.

Finally, once you have made all of your queries, you should output a line in the form ! p_1 p_2 ... p_N, where p is the permutation which you believe is Josh's permutation.

If at any point you format your queries incorrectly, or ask more than 4×105 queries, the interactor will respond with 1 on a single line. After receiving this feedback, you should terminate your program to receive a Wrong Answer verdict; otherwise, your program will receive an arbitrary verdict.

If you successfully guess the correct sequence, then you will receive an Accepted verdict for that test case. Your final score for the problem will be determined through the aforementioned scoring mechanism. You will be told the number of queries that you used.

Please note that you may need to flush stdout after each operation, or interaction may halt. In C++, this can be done with fflush(stdout) or cout << flush (depending on whether you use printf or cout). In Java, this can be done with System.out.flush(). In Python, you can use sys.stdout.flush().

Sample Interaction

>>> denotes your output. Do not print this out.

Copy
4
>>> ? 1 2 2
1
>>> ? 3 4 2
0
>>> ? 1 3 3
1
>> ! 4 2 3 1

Explanation

Josh's permutation is 4,2,3,1.

For the first query, both p1 and p2 contain 2 as a factor, so the answer is 1.

For the second query, neither p3 nor p4 contain 2 as a factor, so the answer is 0.

For the third query, p3 contains 3 as a factor, so the answer is 1.

The permutation has been correctly guessed, and the score for this test case would be 100.


Comments

There are no comments at the moment.