페이지를 불러오는 중…
해결한 사람
1
명
정답률
100.00
%
시간 제한
1000
ms
메모리 제한
2048
MB
Everyone knows that Pharaoh Khufu was a great ruler, but many are unaware that he was also a fashion enthusiast. Back in the day, he had pyramids numbered from to , with pyramid () consisting of stones. He also had the latest catalogue of the most fashionable pyramids of the year. The catalogue consists of pyramids numbered from to , with pyramid () consisting of stones.
For any and , such that , we define a range of pyramids to be a sequence . We also define a range of pyramids analogously.
Every day, Khufu would browse the catalogue and choose two ranges of pyramids and where (the values of , , and may be different every day). After that, he would like to know whether it's possible to transform his range to become equal to the catalogue's range . Transforming a range consists of performing the following step an arbitrary number of times: take one stone from a pyramid within the range and move it to an adjacent pyramid within the range.
Your task is to answer multiple questions of the following form. Given four integers , , , and , determine whether it is possible to transform into . Note that the number of stones in each pyramid never actually changes, Khufu only wonders if one range could be transformed into the other one.
You should implement the following procedures:
void init(std::vector<int> A, std::vector<int> B)
can_transform.bool can_transform(int L, int R, int X, int Y)
true if it's possible to transform into and false otherwise.In each call to can_transform:
Consider the following call:
init([1, 2, 3, 4, 5], [2, 2, 2, 4, 5])
Assume the grader then calls can_transform(0, 2, 0, 2). This call should return whether sequence of pyramids can be transformed into . This is indeed possible by moving stone from the last to the first pyramid in the range. Therefore, this call should return true.
Assume the grader then calls can_transform(3, 4, 3, 4). This call should return whether we can transform Khufu's pyramids to or not. The pyramids already look alike. Therefore, this call should return true.
Assume the grader then calls can_transform(0, 2, 1, 3). This call should return whether sequence of pyramids can be transformed into . This is not possible, and thus this call should return false.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 10 | ; ; for each such that |
| 2 | 40 | ; |
| 3 | 20 | and for each such that |
| 4 | 30 | No additional constraints. |
Input format:
N Q
A[0] A[1] ... A[N-1]
B[0] B[1] ... B[N-1]
L[0] R[0] X[0] Y[0]
L[1] R[1] X[1] Y[1]
...
L[Q-1] R[Q-1] X[Q-1] Y[Q-1]
Here, , , , and denote the values of , , and in the -th call to can_transform, respectively.
Output format:
P[0]
P[1]
...
P[Q-1]
Here, is if the -th call to can_transform returns true and otherwise.
N Q
A[0] A[1] ... A[N-1]
B[0] B[1] ... B[N-1]
L[0] R[0] X[0] Y[0]
L[1] R[1] X[1] Y[1]
...
L[Q-1] R[Q-1] X[Q-1] Y[Q-1]
Here, , , , and denote the values of , , and in the -th call to can_transform, respectively.
P[0]
P[1]
...
P[Q-1]
Here, is if the -th call to can_transform returns true and otherwise.
5 3
1 2 3 4 5
2 2 2 4 5
0 2 0 2
3 4 3 4
0 2 1 3
1
1
0
International Olympiad in Informatics (IOI) 2024, official task package; Korean translation by Reporch.
Reporch에서 한국어 번역, 수식 표기, 이미지 호스팅 및 형식을 수정했습니다.
로그인 상태를 확인하는 중입니다.