#include <vector>
#include <numeric>
// Global prefix sum arrays to store cumulative stone counts
std::vector<long long> prefA;
std::vector<long long> prefB;
/**
* Initializes the prefix sum arrays for Khufu's pyramids and the catalogue.
* A and B are arrays of length N[cite: 20].
*/
void init(std::vector<int> A, std::vector<int> B) {
int n = A.size();
// Use long long to prevent overflow as A[i] can be up to 10^9
prefA.assign(n + 1, 0);
prefB.assign(n + 1, 0);
for (int i = 0; i < n; ++i) {
prefA[i + 1] = prefA[i] + A[i];
prefB[i + 1] = prefB[i] + B[i];
}
}
/**
* Determines if range A[L..R] can be transformed into B[X..Y][cite: 22].
* Transformation is possible if the total number of stones is equal[cite: 13, 32].
*/
bool can_transform(int L, int R, int X, int Y) {
// Calculate the sum of stones in the given ranges using prefix sums
// Range sum formula: pref[end + 1] - pref[start]
long long sumA = prefA[R + 1] - prefA[L];
long long sumB = prefB[Y + 1] - prefB[X];
// If total stones match, Khufu can transform the range [cite: 15, 33]
return sumA == sumB;
}