| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 2048 MB | 430 | 30 | 27 | 12.273% |
Robert is designing a new computer game. The game involves one hero, $n$ opponents and $n + 1$ dungeons. The opponents are numbered from 0ドル$ to $n - 1$ and the dungeons are numbered from 0ドル$ to $n$. Opponent $i$ (0ドル \le i \le n - 1$) is located in dungeon $i$ and has strength $s[i]$. There is no opponent in dungeon $n$.
The hero starts off entering dungeon $x,ドル with strength $z$. Every time the hero enters any dungeon $i$ (0ドル \le i \le n - 1$), they confront opponent $i,ドル and one of the following occurs:
Note $p[i]$ may be less than, equal to, or greater than $s[i]$. Also, $l[i]$ may be less than, equal to, or greater than $i$. Regardless of the outcome of the confrontation, the opponent remains in dungeon $i$ and maintains strength $s[i]$.
The game ends when the hero enters dungeon $n$. One can show that the game ends after a finite number of confrontations, regardless of the hero's starting dungeon and strength.
Robert asked you to test his game by running $q$ simulations. For each simulation, Robert defines a starting dungeon $x$ and starting strength $z$. Your task is to find out, for each simulation, the hero's strength when the game ends.
You should implement the following procedures:
void init(int n, int[] s, int[] p, int[] w, int[] l)
simulate (see below).int64 simulate(int x, int z)
Consider the following call:
init(3, [2, 6, 9], [3, 1, 2], [2, 2, 3], [1, 0, 1])
The diagram above illustrates this call. Each square shows a dungeon. For dungeons 0ドル,ドル 1ドル$ and 2ドル,ドル the values $s[i]$ and $p[i]$ are indicated inside the squares. Magenta arrows indicate where the hero moves after winning a confrontation, while black arrows indicate where the hero moves after losing.
Let's say the grader calls simulate(0, 1).
The game proceeds as follows:
| Dungeon | Hero's strength before confrontation | Result |
|---|---|---|
| 0ドル$ | 1ドル$ | Lose |
| 1ドル$ | 4ドル$ | Lose |
| 0ドル$ | 5ドル$ | Win |
| 2ドル$ | 7ドル$ | Lose |
| 1ドル$ | 9ドル$ | Win |
| 2ドル$ | 15ドル$ | Win |
| 3ドル$ | 24ドル$ | Game ends |
As such, the procedure should return 24ドル$.
Let's say the grader calls simulate(2, 3).
The game proceeds as follows:
| Dungeon | Hero's strength before confrontation | Result |
|---|---|---|
| 2ドル$ | 3ドル$ | Lose |
| 1ドル$ | 5ドル$ | Lose |
| 0ドル$ | 6ドル$ | Win |
| 2ドル$ | 8ドル$ | Lose |
| 1ドル$ | 10ドル$ | Win |
| 2ドル$ | 16ドル$ | Win |
| 3ドル$ | 25ドル$ | Game ends |
As such, the procedure should return 25ドル$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 11 | $n \le 50,000円,ドル $q \le 100,ドル $s[i], p[i] ≤ 10,000円$ (for all 0ドル \le i \le n - 1$) |
| 2 | 26 | $s[i] = p[i]$ (for all 0ドル \le i \le n - 1$) |
| 3 | 13 | $n \le 50,000円,ドル all opponents have the same strength, in other words, $s[i] = s[j]$ for all 0ドル \le i, j \le n - 1$. |
| 4 | 12 | $n \le 50,000円,ドル there are at most 5ドル$ distinct values among all values of $s[i]$. |
| 5 | 27 | $n \le 50,000円$ |
| 6 | 11 | No additional constraints. |
The sample grader reads the input in the following format:
simulate.The sample grader prints your answers in the following format:
simulate.C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)