Contest Day 2 - JOI Open Contest
Anna invented a secret binary operation . For non-negative integers
,
less than or equal to
, a non-negative integer
less than or equal to
is determined. This operation
is associative. Namely, the equality
holds for non-negative integers
,
,
less than or equal to
. This value is simply denoted by
.
Anna planned to play a game with Bruno. She asked him to guess the operation . She showed
integers
to him. She gave to him a number of queries of the following form: "What is the value of
?"
Bruno said it is difficult to play this game without hints. Anna decided to give hints to him. Each hint is given as follows: he will choose ,
to ask the value of
, and she will tell him the value of
. He can ask for hints when the integers
are given in the beginning of the game. He can also ask for hints when she gives a query to him. Of course, he would like to reduce the number of hints. Because he would like to behave as if he knows almost everything about the operation
, he would especially like to reduce the number of hints after a query is given to him.
Task
Write a program which implements Bruno's strategy to ask for hints and answer Anna's queries correctly.
Implementation Details
You should write a program which implements the strategy to ask for hints and answer Anna's queries. Your program should include the header file secret.h
by #include "secret.h"
Your program should implement the following procedures.
void Init(int N, int A[])
This procedure is called only once in the beginning. The parameter
is the number
of the integers shown by Anna. The parameter
is an array of length
. The elements
are the integers
shown by her.
int Query(int L, int R)
This procedure is called when Anna gives a query to Bruno. This means she is asking the value of
.
The following procedure can be called by your program.
- This procedure is called when Bruno asks for a hint. This means he is asking about the value of
int Secret(int X, int Y)
. The parameters
and
should be integers satisfying
and
. If this procedure is called with parameters not satisfying this condition, your program is considered as Wrong Answer [1] and terminated.
This procedure returns the value of.
Constraints
All input data satisfy the following conditions.
.
.
- The number of calls to
Query
is less than or equal to.
Grading
The score will be given to your program if your program terminates successfully for each test case, it is not considered as Wrong Answer [1], and it returns the correct value for each call to Query
.
Your score is calculated as follows.
- Your score is
if the following two conditions are satisfied for each test case:
- In
Init
, the number of calls toSecret
is less than or equal to.
- In each call to
Query
, the number of calls toSecret
is less than or equal to.
- In
- Your score is
if your program does not satisfy (1), and the following two conditions are satisfied:
- In
Init
, the number of calls toSecret
is less than or equal to.
- In each call to
Query
, the number of calls toSecret
is less than or equal to.
- In
- Your score is
if your program does not satisfy (1) or (2).
Comments