Sequence and Queries 37

Interview

Time limit1sMemory limit512 MB

Summary
Maintain an array under point updates, and for range queries report how many entries are even or odd.
Level

Easy3 of 10

Topics
Array, Prefix sum, Segment tree, Implementation
Solved
No attempts yet

Problem

There is a sequence A1,A2,…,ANA_1, A_2, \dots, A_N of length NN. Write a program that performs the following queries.

  • 1 i x: set AiA_i to xx.
  • 2 l r: print the number of even values among all AiA_i with l≤i≤rl \le i \le r.
  • 3 l r: print the number of odd values among all AiA_i with l≤i≤rl \le i \le r.

The sequence is indexed starting from 1.

Input

The first line gives the size of the sequence NN (1≤N≤100 0001 \le N \le 100\,000).

The second line gives A1,A2,…,ANA_1, A_2, \dots, A_N. (1≤Ai≤1091 \le A_i \le 10^9)

The third line gives the number of queries MM (1≤M≤100 0001 \le M \le 100\,000).

Each of the next MM lines gives one query. (1≤i≤N1 \le i \le N, 1≤l≤r≤N1 \le l \le r \le N, 1≤x≤1091 \le x \le 10^9)

Output

Print the answers to queries of type 2 and 3, one per line.

Examples1

  1. Example 1

    Input
    6
    1 2 3 4 5 6
    4
    2 2 5
    3 1 4
    1 5 4
    2 1 6
    
    Expected output
    2
    2
    4