#4621. [UOI 2024] Football

[UOI 2024] Football

[UOI 2024] Football

题目描述

There are $n$ players in a football team, numbered with integers from $1$ to $n$. The skill level of player with number $i$ is described by the integer $c_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 1≤i<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,…,km−1]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((i−1)mod  m)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,…,aq−1a_0,a_1,\ldots,a_{q-1} is given. For each ii from 00 to (q−1)(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 $n$ and $q$ $(1 \leq n, q \leq 3\cdot{10}^5)$ --- the number of players and the length of the array $a$.

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

The third line contains qq integers a0,a1,…,aq−1a_0, a_1, \dots, a_{q-1} (1≤ai≤n−1)(1 \leq a_i \leq n-1) --- the elements of the array aa.

输出格式

Output $q$ 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,q≤100n, q \leq 100;
  • (44 points): all values of aia_i are the same;
  • (1111 points): nn is a prime number;
  • (1212 points): n,q≤1000n, q \leq 1000;
  • (1616 points): n,q≤1.5⋅105n, q \leq 1.5\cdot{10}^5, n=2kn = 2^k for some integer kk;
  • (2525 points): n,q≤105n, q \leq {10}^5;
  • (2222 points): without additional constraints. 标签: P12557|2024|UOI(乌克兰)

来源

P12557|[UOI 2024] Football