| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 5 초 | 2048 MB | 12 | 4 | 4 | 33.333% |
JOI-kun is planning a lottery event. In this lottery event, an even number of bags will be used. Each bag initially contains some red balls and blue balls (possibly zero). Participants will keep coming to the lottery event until at least one of the bags becomes empty. Each participant draws one ball from each bag. If the total number of red and blue balls they have drawn ends up being equal, they receive one prize. Balls drawn are not returned to the bags.
As preparation, JOI-kun has prepared $N$ bags, numbered from 0ドル$ to $N − 1$. Bag $i$ (0ドル ≤ i ≤ N − 1$) contains $X_i$ red balls and $Y_i$ blue balls.
In the lottery event, some of the $N$ bags will be selected for use. There are $Q$ plans for selecting bags. In the $j$-th plan (1ドル ≤ j ≤ Q$), the bags $L_j , L_{j + 1}, \dots , R_j$ are used. Here, $R_j − L_j + 1$ is even.
To prepare the prizes for the event, JOI-kun wants to know, for each plan, the maximum possible total number of prizes participants can obtain. Write a program that, given the bag contents and the plans, returns the maximum possible total number of prizes participants can obtain for each plan.
You need to submit one file.
The file is lottery.cpp. The program should include lottery.h using the preprocessing directive #include.
In lottery.cpp, the following functions should be implemented.
void init(int N, int Q, std::vector<int> X, std::vector<int> Y)
N is the number of bags $N$ prepared by JOI-kun.Q is the number of plans $Q$ for selecting bags.X is an array of length $N$. X[i] (0ドル ≤ i ≤ N − 1$) is the number of red balls in bag $i$.Y is an array of length $N$. Y[i] (0ドル ≤ i ≤ N − 1$) is the number of blue balls in bag $i$.int max_prize(int L, int R)
init is called.L is the value $L_j$ of the $j$-th plan.R is the value $R_j$ of the $j$-th plan.Important Notices
You can download an archive file from the contest webpage which contains the sample grader to test your program. The archive file also contains a sample source file of your program.
The sample grader is the file grader.cpp. To test your program, place the files grader.cpp, lottery.cpp, and lottery.h in the same directory, and compile them using the following command:
g++ -std=gnu++20 -O2 -o grader grader.cpp lottery.cpp
Alternatively, you can execute the compile.sh file included in the archive by running:
./compile.sh
If the compilation is successful, an executable file named grader will be generated.
Note that the actual grader is different from the sample grader. The sample grader will be executed as a single process, which will read input data from the standard input and write the results to the standard output.
Input for the Sample Grader
The sample grader reads input from standard input in the following format:
$N$ $Q$
$X_0$ $X_1$ $\cdots$ $X_{N−1}$
$Y_0$ $Y_1$ $\cdots$ $Y_{N−1}$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_Q$ $R_Q$
Output of the Sample Grader
The sample grader outputs the return value of function max_prize in one line to the standard output, after every call of this function.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 16 | $Q ≤ 100,ドル $X_i ≤ 100,ドル $Y_i ≤ 100$ (0ドル ≤ i ≤ N − 1$), $R_j − L_j + 1 ≤ 100$ (1ドル ≤ j ≤ Q$). |
| 2 | 16 | $Q ≤ 100,ドル $R_j − L_j + 1 ≤ 100$ (1ドル ≤ j ≤ Q$). |
| 3 | 19 | $Q ≤ 200,円 000,ドル $L_j ≤ L_{j+1},ドル $R_j ≤ R_{j+1}$ (1ドル ≤ j ≤ Q − 1$). |
| 4 | 12 | $N ≤ 20,円 000,ドル $Q ≤ 50,円 000$. |
| 5 | 14 | $N ≤ 100,円 000,ドル $Q ≤ 200,円 000$. |
| 6 | 23 | No additional constraints. |
5 3 2 1 3 1 0 1 1 0 2 0 0 3 1 4 2 3
2 0 2
| Function Calls | Return Values |
|---|---|
init(5, 3, [2, 1, 3, 1, 0], [1, 1, 0, 2, 0]) |
|
max_prize(0, 3) |
2ドル$ |
max_prize(1, 4) |
0ドル$ |
max_prize(2, 3) |
2ドル$ |
In the first call to max_prize, bags 0ドル,ドル 1ドル,ドル 2ドル,ドル 3ドル$ are used. If participants draw balls in the following way, the total number of prizes obtained will be 2ドル$:
It is not possible for participants to obtain more than 2ドル$ prizes. Therefore, the first call to max_prize must return 2ドル$.
In the second call to max_prize, bags 1ドル,ドル 2ドル,ドル 3ドル,ドル 4ドル$ are used. Since bag 4ドル$ is empty from the beginning, the lottery event ends without any participant drawing a ball. Therefore, the second call to max_prize must return 0ドル$.
In the third call to max_prize, bags 2ドル,ドル 3ドル$ are used. If participants draw balls in the following way, the total number of prizes obtained will be 2ドル$:
It is not possible for participants to obtain more than 2ドル$ prizes. Therefore, the third call to max_prize must return 2ドル$.
This sample input satisfies the constraints of subtasks 1, 2, 4, 5, and 6.
6 5 1 3 3 2 1 0 1 2 1 1 2 1 0 1 1 2 1 4 2 5 4 5
2 3 3 1 1
| Function Calls | Return Values |
|---|---|
init(6, 5, [1, 3, 3, 2, 1, 0], [1, 2, 1, 1, 2, 1]) |
|
max_prize(0, 1) |
2ドル$ |
max_prize(1, 2) |
3ドル$ |
max_prize(1, 4) |
3ドル$ |
max_prize(2, 5) |
1ドル$ |
max_prize(4, 5) |
1ドル$ |
This sample input satisfies the constraints of all subtasks.
C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)