Logo
(追記) (追記ここまで)

34352번 - Lottery 서브태스크다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 2048 MB124433.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)
  • This function is called only once, at the beginning.
  • The parameter N is the number of bags $N$ prepared by JOI-kun.
  • The parameter Q is the number of plans $Q$ for selecting bags.
  • The parameter X is an array of length $N$. X[i] (0ドル ≤ i ≤ N − 1$) is the number of red balls in bag $i$.
  • The parameter 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)
  • This function is called $Q$ times after the function init is called.
  • On the $j$-th call (1ドル ≤ j ≤ Q$) of this function:
    • The parameter L is the value $L_j$ of the $j$-th plan.
    • The parameter R is the value $R_j$ of the $j$-th plan.
    • This function must return the maximum possible total number of prizes participants can obtain in the $j$-th plan.

Important Notices

  • Your program can implement other functions for internal use, or use global variables.
  • Your program must not use the standard input and the standard output. Your program must not communicate with other files by any methods. However, your program may output debugging information to the standard error.

컴파일과 테스트 실행

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.

입력

출력

제한

  • 2ドル ≤ N ≤ 200,円 000$.
  • 1ドル ≤ Q ≤ 500,円 000$.
  • 0ドル ≤ X_i ≤ 10^9$ (0ドル ≤ i ≤ N − 1$).
  • 0ドル ≤ Y_i ≤ 10^9$ (0ドル ≤ i ≤ N − 1$).
  • 0ドル ≤ L_j < R_j ≤ N − 1$ (1ドル ≤ j ≤ Q$).
  • $R_j − L_j + 1$ is even (1ドル ≤ j ≤ Q$).
  • Given values are all integers.

서브태스크

번호배점제한
116

$Q ≤ 100,ドル $X_i ≤ 100,ドル $Y_i ≤ 100$ (0ドル ≤ i ≤ N − 1$), $R_j − L_j + 1 ≤ 100$ (1ドル ≤ j ≤ Q$).

216

$Q ≤ 100,ドル $R_j − L_j + 1 ≤ 100$ (1ドル ≤ j ≤ Q$).

319

$Q ≤ 200,円 000,ドル $L_j ≤ L_{j+1},ドル $R_j ≤ R_{j+1}$ (1ドル ≤ j ≤ Q − 1$).

412

$N ≤ 20,円 000,ドル $Q ≤ 50,円 000$.

514

$N ≤ 100,円 000,ドル $Q ≤ 200,円 000$.

623

No additional constraints.

예제 입력 1

5 3
2 1 3 1 0
1 1 0 2 0
0 3
1 4
2 3

예제 출력 1

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ドル$:

  • The first participant draws a red ball, a blue ball, a red ball, and a blue ball from bags 0ドル,ドル 1ドル,ドル 2ドル,ドル 3ドル,ドル respectively. Since the number of red and blue balls drawn is equal, they receive one prize.
  • The second participant draws a blue ball, a red ball, a red ball, and a blue ball from bags 0ドル,ドル 1ドル,ドル 2ドル,ドル 3ドル,ドル respectively. Since the number of red and blue balls drawn is equal, they receive one prize.
  • At this point, bag 1ドル$ becomes empty, and the lottery event ends.

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ドル$:

  • The first participant draws a red ball and a red ball from bags 2ドル$ and 3ドル,ドル respectively. Since the number of red and blue balls drawn is not equal, they do not receive a prize.
  • The second participant draws a red ball and a blue ball from bags 2ドル$ and 3ドル,ドル respectively. Since the number of red and blue balls drawn is equal, they receive one prize.
  • The third participant draws a red ball and a blue ball from bags 2ドル$ and 3ドル,ドル respectively. Since the number of red and blue balls drawn is equal, they receive one prize.
  • At this point, bags 2ドル$ and 3ドル$ become empty, and the lottery event ends.

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.

예제 입력 2

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

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.

힌트

출처

Contest > JOI Open Contest > JOI Open Contest 2025 2번

제출할 수 있는 언어

C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /