Shil and Magic of Arrays

4.5

2 votes
Ready, Mathematics, Hard, Approved, Sqrt-Decomposition, Mathematics, Mathamatics
Problem

Shil has an array of N elements A1 , A2 .... AN . He wants to perform two types of operations on this array.

  • 1 i K: Update the value of Ai to K i.e do Ai = K
  • 2 P : Find the magical value of subarray A1, A2 .... AP
The magical value of array B1 , B2 .... Br is defined as product of (f[i]+1)(f[i]+1) where f[i] is the number of times i occurs in array B.

Input:
First line of input contains N and Q denoting length of array A and number of operations to be performed respectively. Next Q lines consists of operations of type 1 or type 2 in the format mentioned above. Each element of array is initially initialized to 0.

Output:
For each operation of type 2 , output the magical value modulo 109 + 7.

Constraints:

  • 1 ≤ N ≤ 2 * 105
  • 1 ≤ Q ≤ 2 * 105
  • 1 ≤ P, K ≤ N

Sample Input
8 8
1 3 6
2 2
2 8
2 7
2 6
1 1 6
2 6
2 1
Sample Output
27
67108864
3294172
186624
84375
4
Time Limit: 4
Memory Limit: 512
Source Limit:
Explanation

In first query , we update A3 to 6.
Answer for second query will be ( f[0]+1)(f[0]+1) , thats 33
Answer for third query will be ( f[0]+1)(f[0]+1) * ( f[6]+1)(f[6]+1) , thats 88 * 22

Editor Image

?