Pyramids

시간 제한1초메모리 제한1024 MB

요약
두 배열이 주어질 때, 한 부분 배열의 돌을 인접한 위치로 하나씩 옮겨 같은 길이의 다른 부분 배열로 만들 수 있는지 묻는 질의에 답한다.
난이도

어려움10점 중 8점

유형
누적 합, 수학, 배열, 해시맵
정답자
아직 제출이 없습니다

문제

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 NN pyramids numbered from 00 to N−1N - 1, with pyramid ii (0≤i<N0 ≤ i < N) consisting of A\[i]A\[i] stones. He also had the latest catalogue of the most fashionable pyramids of the year. The catalogue consists of NN pyramids numbered from 00 to N−1N - 1, with pyramid ii (0≤i<N0 ≤ i < N) consisting of B\[i]B\[i] stones.

For any xx and yy, such that 0≤x≤y<N0 ≤ x ≤ y < N, we define a range of pyramids A\[x..y]A\[x..y] to be a sequence A\[x],A\[x+1],…,A\[y]A\[x], A\[x + 1], \dots , A\[y]. We also define a range of pyramids B\[x..y]B\[x..y] analogously.

Every day, Khufu would browse the catalogue and choose two ranges of pyramids A\[L..R]A\[L..R] and B\[X..Y]B\[X..Y ] where R−L=Y−XR - L = Y - X (the values of LL, RR, XX and YY may be different every day). After that, he would like to know whether it's possible to transform his range A\[L..R]A\[L..R] to become equal to the catalogue's range B\[X..Y]B\[X..Y ]. 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 LL, RR, XX, and YY, determine whether it is possible to transform A\[L..R]A\[L..R] into B\[X..Y]B\[X..Y ]. 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.

제한

  • 1≤N≤100,0001 ≤ N ≤ 100\\, 000
  • 1≤Q≤100,0001 ≤ Q ≤ 100\\, 000
  • 1≤A\[i]≤1091 ≤ A\[i] ≤ 10^9
  • 1≤B\[i]≤1091 ≤ B\[i] ≤ 10^9

In each call to can_transform:

  • 0≤L≤R<N0 ≤ L ≤ R < N
  • 0≤X≤Y<N0 ≤ X ≤ Y < N
  • R−L=Y−XR - L = Y - X

예제

이 문제는 공개된 예제가 없습니다.