Bubble Cup V9 G Heroes of Making Magic III

View as PDF

Submit solution


Points: 20
Time limit: 2.5s
Memory limit: 64M

Problem type

I'm strolling on sunshine, yeah-ah! And don't it feel good!

Well, it certainly feels good for our Heroes of Making Magic, who are casually walking on a one-directional road, fighting imps. Imps are weak and feeble creatures and they are not good at much. However, Heroes enjoy fighting them. For fun, if nothing else.

Our Hero, Ignatius, simply adores imps. He is observing a line of imps, represented as a zero-indexed array of integers A[\,] of length N, where A[i] denotes the number of imps at the i^{th} position. Sometimes, imps can appear out of nowhere.

When heroes fight imps, they select a segment of the line, start at one end of the segment, and finish on the other end, without ever exiting the segment. They can move exactly one cell left or right from their current position and when they do so, they defeat one imp on the cell that they moved to, so, the number of imps on that cell decreases by one. This also applies when heroes appear at one end of the segment, at the beginning of their walk.

Their goal is to defeat all imps on the segment, without ever moving to an empty cell in it (without imps), since they would get bored. Since Ignatius loves imps, he doesn't really want to fight them, so no imps are harmed during the events of this task. However, he would like you to tell him whether it would be possible for him to clear a certain segment of imps in the abovementioned way if he wanted to.

You are given Q queries, which have two types:

  1. a b k - denotes that k imps appear at each cell from the interval [a,b].
  2. a b - asks whether Ignatius could defeat all imps in the interval [a,b] in the way described above.

Input Specification

The first line contains a single integer, N, the length of A. The following line contains N integers, A[i], the initial number of imps in each cell. The third line contains a single integer Q, the number of queries. The remaining Q lines contain one query each, with a,b and k.

Output Specification

For each second type of query output 1 if it is possible to clear the segment, and 0 if it is not.

Constraints

  • 1 \le N \le 200\,000
  • 1 \le Q \le 300\,000
  • 0 \le A[i] \le 5000
  • 0 \le a \le b < N
  • 0 \le k \le 5000

Sample Input

3
2 2 2
3
2 0 2
1 1 1 1
2 0 2

Sample Output

0
1

Explanation

For the first query, one can easily check that it is indeed impossible to get from the first to the last cell while clearing everything. After we add 1 to the second position, we can clear the segment, for example by moving in the following way: 0 \to 1 \to 2 \to 1 \to 0 \to 1 \to 2


Comments

There are no comments at the moment.