Shil and Magic of Arrays
Tag(s):

Hard, Mathematics, Mathematics, Sqrt-Decomposition

Problem
Editorial
Analytics

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
Explanation

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

Time Limit: 4.0 sec(s) for each input file.
Memory Limit: 512 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...

This Problem was Asked in Challenge Name

October Circuits

OTHER PROBLEMS OF THIS CHALLENGE
• Basic Programming > Implementation
• Math > Combinatorics
• Algorithms > Graphs
• Algorithms > Graphs
• Algorithms > Graphs
• Algorithms > Graphs