시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 13 8 8 61.538%

문제

Anna invented a secret binary operation ★. For non-negative integers x, y less than or equal to 1 000 000 000, a non-negative integer x ★ y less than or equal to 1 000 000 000 is determined. This operation ⋆ is associative. Namely, the equality (x ★ y) ★ z = x ★ (y ★ z) holds for non-negative integers x, y, z less than or equal to 1 000 000 000. This value is simply denoted by x ★ y ★ z.

Anna planned to play a game with Bruno. She asked him to guess the operation ★. She showed N integers A0, A1, . . . , AN−1 to him. She gave to him a number of queries of the following form: “What is the value of AL ★ AL+1 ★ · · · ★ AR?”

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 x, y to ask the value of x ★ y, and she will tell him the value of x ★ y. He can ask for hints when the integers A0, A1, . . . , AN−1 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.

Write a program which implements Bruno’s strategy to ask for hints and answer Anna’s queries correctly.

구현

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 N is the number N of the integers shown by Anna. The parameter A is an array of length N. The elements A[0], A[1], . . . , A[N-1] are the integers A0, A1, . . . , AN−1 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 AL ★ AL+1 ★ · · · ★ AR (0 ≤ L ≤ R ≤ N − 1).
    • This procedure should return the value of AL ★ AL+1 ★ · · · ★ AR. The following procedure can be called in your program.
  • int Secret(int X, int Y)
    • This procedure is called when Bruno asks for a hint. This means he is asking about the value of X ★ Y. The parameters X and Y should be integers X and Y satisfying 0 ≤ X ≤ 1 000 000 000 and 0 ≤ Y ≤ 1 000 000 000. 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 X ★ Y.

입력

The sample grader reads the following data from the standard input.

  • The first line contains an integer N, the number of the integers shown by Anna.
  • The second line contains space separated integers A0, A1, . . . , AN−1, the integers shown by Anna.
  • The third line contains an integer Q, the number of queries given by Anna.
  • The (j + 1)-st line (0 ≤ j ≤ Q − 1) of the following Q lines contains space separated integers Lj and Rj (0 ≤ Lj ≤ Rj ≤ N − 1). This means, in the (j + 1)-st query, Anna asks the value of ALj ★ ALj+1 ★ · · · ★ ARj .

출력

When the program terminates successfully, the sample grader writes to the standard output the values returned by Query one per line. It also writes the following information to the standard error.

  • If your program is considered as Wrong Answer [1], it writes “Wrong Answer [1]”. (The quotation mark is not written actually.)
  • If your program is not considered as Wrong Answer [1], it writes the number of calls to Secret in the procedure Init, and the maximum number of calls to Secret in each call to the procedure Query.

제한

  • 1 ≤ N ≤ 1 000.
  • 0 ≤ Ai ≤ 1 000 000 000 (0 ≤ i ≤ N − 1).
  • The number of calls to Query is less than or equal to 10 000.

점수

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.

  • (1) Your score is 100 if the following two conditions are satisfied for each test case:
    • In Init, the number of calls to Secret is less than or equal to 8 000.
    • In each call to Query, the number of calls to Secret is less than or equal to 1.
  • (2) Your score is 30 if your program does not satisfy (1), and the following two conditions are satisfied:
    • In Init, the number of calls to Secret is less than or equal to 8 000.
    • In each call to Query, the number of calls to Secret is less than or equal to 20.
  • (3) Your score is 6 if your program does not satisfy (1) or (2).

예제

Here is a sample input for the sample grader and examples of interactions between the procedures. Note that the the following return values are correct if the sample grader is used.

Input

8
1 4 7 2 5 8 3 6
4
0 3
1 7
5 5
2 4
Call Return
Init(8, [1, 4, 7, 2, 5, 8, 3, 6]) None
Query(0, 3) 13
Query(1, 7) 32
Query(5, 5) 8
Query(2, 4) 13

The procedure Secret can be called in the procedure Init or the procedure Query. For example, when Secret(4, 7) is called, the return value is 10 because 4 ★ 7 = 10 if the sample grader is used.

The value of 1 ★ 4 ★ 7 ★ 2 is asked in the first query. Since

1 ★ 4 ★ 7 ★ 2 = (1 ★ (4 ★ 7)) ★ 2 = (1 ★ 10) ★ 2 = 11 ★ 2 = 13

holds if the sample grader is used, the procedure Query should return 13.

제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 100점 이상을 획득해야 를 받는다.
  • 예제는 채점하지 않는다.