#P13691. [CEOI 2025] highest

    ID: 15180 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>倍增2025交互题CEOI(中欧)ST 表

[CEOI 2025] highest

Problem Description

In an alternate universe, Vlad is stuck inside a futuristic version of the Poenari Fortress, now spanning nn floors, numbered 00 through n−1n - 1. From each floor ii (0≤i≤n−10 \leq i \leq n - 1), he can only go up, either by taking the stairs and paying 11 drop of blood (this is the currency that vampires use to pay in Romania), or by turning into a bat and traversing the vents, for which he has to pay 22 drops of blood. The stairs can take him up to v[i]v[i] floors upwards, while the vents span up to w[i]w[i] floors upwards, where vv and ww are two given arrays: v=v[0],v[1],…,v[n−1]v = v[0], v[1], \ldots, v[n - 1] and w=w[0],w[1],…,w[n−1]w = w[0], w[1], \ldots, w[n - 1].

Formally, from floor ii (0≤i≤n−10 \leq i \leq n - 1), Vlad can go:

  • anywhere from floor i+1i + 1 to floor i+v[i]i + v[i] without exceeding n−1n - 1, for a cost of 11
  • anywhere from floor i+1i + 1 to floor i+w[i]i + w[i] without exceeding n−1n - 1, for a cost of 22

Furthermore, his brothers Radu and Mircea proposed mm scenarios for Vlad, each one consisting of two floors AA and BB (A≤BA \leq B). Vlad has to answer their mm questions: what is the least amount of blood that he has to sacrifice to get from floor AA to floor BB?

Implementation Details

You will have to implement the function solve:

std::vector<int> solve(std::vector<int> &v, std::vector<int> &w, std::vector<std::pair<int,int>> &queries);
  • Receives the vectors vv, the heights of the flights of stairs, and ww, the heights of the vent systems, starting at each floor, both of them of size nn.
  • Also receives the queries, a vector of pairs of size mm. Each pair contains AA and BB as described in the statement.
  • Returns a vector of size mm, consisting of the answers to the mm queries.
7
2 3 1 1 1 1 2
3 4 1 2 1 2 2
3
0 4
0 5
0 6
2
3
4
10
1 1 1 2 3 2 1 1 2 3 
2 4 1 4 1 4 1 3 2 3 
5
3 9
0 9
0 7
0 4
3 5
3
5
4
3
1

Hint

Sample Explanation 1

Consider the following call:

solve({2, 3, 1, 1, 1, 1, 2}, {3, 4, 1, 2, 1, 2, 2}, {{0, 4}, {0, 5}, {0, 6}})

Here we have n=7n = 7 and 33 queries, v=[2,3,1,1,1,1,2]v = [2, 3, 1, 1, 1, 1, 2] and w=[3,4,1,2,1,2,2]w = [3, 4, 1, 2, 1, 2, 2].

For the first query (0,4)(0, 4), Vlad has to make two 11-cost jumps: 00 to 11 (even though he can jump to 22, floor 11 will then take him further), then 11 to 44. Total cost: 1+1=21 + 1 = 2.

For the second query (0,5)(0, 5), there are 22 optimal paths: 00 to 11 (cost 11), 11 to 44 (cost 11), 44 to 55 (cost 11); the second path is 00 to 11 (cost 11), 11 to 55 (cost 22). Total cost: 1+1+1=1+2=31 + 1 + 1 = 1 + 2 = 3.

For the third query (0,6)(0, 6), one example path of cost 44 is 00 to 11 (cost 11), 11 to 55 (cost 22), 55 to 66 (cost 11). Total cost: 1+2+1=41 + 2 + 1 = 4.

So the vector that the function will return must be: {2,3,4}\{2, 3, 4\}

Sample Explanation 2

Consider the following call:

solve({1, 1, 1, 2, 3, 2, 1, 1, 2, 3}, {2, 4, 1, 4, 1, 4, 1, 3, 2, 3}, {{3, 9}, {0, 9}, {0, 7}, {0, 4}, {3, 5}})

These are the optimal paths for the queries:

  • (3,9)(3, 9): 33 to 55 (cost 11), 55 to 99 (cost 22) ⇒\Rightarrow total: 33
  • (0,9)(0, 9): 00 to 11 (cost 11), 11 to 55 (cost 22), 55 to 99 (cost 22) ⇒\Rightarrow total: 55
  • (0,7)(0, 7): 00 to 11 (cost 11), 11 to 55 (cost 22), 55 to 77 (cost 11) ⇒\Rightarrow total: 44
  • (0,4)(0, 4): 00 to 11 (cost 11), 11 to 44 (cost 22) ⇒\Rightarrow total: 33
  • (3,5)(3, 5): 33 to 55 (cost 11) ⇒\Rightarrow total: 11

So the vector that the function will return must be: {3,5,4,3,1}\{3, 5, 4, 3, 1\}

Constraints

  • 1≤n,m≤5000001 \leq n, m \leq 500000
  • 1≤v[i],w[i]≤n1 \leq v[i], w[i] \leq n for all 0≤i≤n−10 \leq i \leq n - 1
  • 0≤A≤B≤n−10 \leq A \leq B \leq n - 1 for all queries

Subtasks

  1. (5 points) 1≤n≤300,1≤m≤5000001 \leq n \leq 300, 1 \leq m \leq 500000
  2. (7 points) 1≤n≤3000,1≤m≤30001 \leq n \leq 3000, 1 \leq m \leq 3000
  3. (11 points) 1≤n≤20000,1≤m≤200001 \leq n \leq 20000, 1 \leq m \leq 20000
  4. (44 points) 1≤n≤200000,1≤m≤2000001 \leq n \leq 200000, 1 \leq m \leq 200000
  5. (8 points) $1 \leq n \leq 500000, 1 \leq m \leq 500000, v[i] \leq v[j]$ and w[i]≤w[j]w[i] \leq w[j] for all 0≤i<j≤n−10 \leq i < j \leq n - 1
  6. (25 points) No further restrictions