Zeus and Fibonacci
Practice
3 (1 votes)
Approved
Data structures
Hard
Matrix
Segment trees
Problem
42% Success 628 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array A consisting of N integers. You have to process two types of queries on this array.
Type 1: Change the ith element to X
Type 2: Given l and r, calculate: \(\sum_{i=l}^{r} \sum_{j=i}^{r} Fib ( \sum_{k=i}^{j} A_k ) \)

Note: \(Fib(i)\) is the ith Fibonacci number. \(Fib(0)=0 \space.\space Fib(1)=1 \)

Input

First line contains an integer N.
Next line contains N space separated integers denoting array A.
Next line contains the integer Q.
Next Q lines are of the following format:
\(1 \space i \space X\) : for type 1 query
\(2 \space l \space r\) : for type 2 query

Output

For each type 2 query output the answer modulo \(10^9+7\) on a new line.

Constraints

\(1 ≤ N,Q ≤ 10^5\)
\(1 ≤ A[i],x ≤ 10^9\)
\(1 ≤ l,r,i ≤ N \)
\(l ≤ r \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
2 votes
Tags:
Segment TreesSegment treeData StructuresAdvanced Data StructuresFenwick Tree
Points:50
26 votes
Tags:
Data StructuresHardOpenSegment TreesTrees
Points:50
3 votes
Tags:
AlgorithmsApprovedHardOpenSegment TreesTrees