#P12557. [UOI 2024] Football

[UOI 2024] Football

题目描述

There are nn players in a football team, numbered with integers from 11 to nn. The skill level of player with number ii is described by the integer cic_i.

The players are arranged in a circle in such a way that the player with number ii has the player with number i+1i+1 on their right side (for 1i<n1 \le i < n), and for the player with number nn, the next player is the one with number 11.

Let's define the strength of a game combination, characterized by an array of integers k=[k0,k1,k2,,km1]k=[k_0, k_1, k_2, \ldots, k_{m-1}], as follows:

  • initially, the ball is with the player with number 11;
  • the players pass the ball in turns indefinitely: when performing the pass with number ii, the player who currently has control of the ball passes it to the player located xx positions to the right in the circle, where x=k((i1)modm)x=k_{((i-1) \mod m)};
  • the strength of the game combination is considered to be the minimum skill level among the skills of all players who had the ball at some point during the described process.

An array of integers a0,a1,,aq1a_0,a_1,\ldots,a_{q-1} is given. For each ii from 00 to (q1)(q-1), find the strength of the game combination characterized by the array [a0,a1,,ai][a_0,a_1,\ldots,a_i].

输入格式

The first line contains two integers nn and qq (1n,q3105)(1 \leq n, q \leq 3\cdot{10}^5) --- the number of players and the length of the array aa.

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (1cin)(1 \leq c_i \leq n) --- the skill levels of the players.

The third line contains qq integers a0,a1,,aq1a_0, a_1, \dots, a_{q-1} (1ain1)(1 \leq a_i \leq n-1) --- the elements of the array aa.

输出格式

Output qq integers --- the sought values of the strengths of game combinations.

6 3
6 3 5 4 2 1
3 1 2
4 1 2

提示

In the example of passing the ball for game combinations, it looks as follows:

k=[3]k=[3]

k=[3,1]k=[3,1]

k=[3,1,2]k=[3,1,2]

Scoring

  • (1010 points): n,q100n, q \leq 100;
  • (44 points): all values of aia_i are the same;
  • (1111 points): nn is a prime number;
  • (1212 points): n,q1000n, q \leq 1000;
  • (1616 points): n,q1.5105n, q \leq 1.5\cdot{10}^5, n=2kn = 2^k for some integer kk;
  • (2525 points): n,q105n, q \leq {10}^5;
  • (2222 points): without additional constraints.