Array revolve
Practice
3.3 (16 votes)
Advanced data structures
Arithmetic progression
Data structures
Lazy propagation
Medium
Segment trees
Problem
89% Success 3999 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array A(1-based index) consisting of N integers. You have to process two types of queries on this array.

Type 1: Given ID and VAL, perform the operation UPDATE(ID, VAL)

    UPDATE(ID, VAL):

        if VAL == 0:

            return

        AID = AID + VAL

        if ID == N:

            UPDATE(1, VAL - 1)

        else :

            UPDATE(ID + 1, VAL - 1)

Type 2: Given L and R, find QUERY(L, R)

    QUERY(L, R):

        if L == R:

            return AL

        if L == N:

            return AL + QUERY(1, R) 

        else :

            return AL + QUERY(L + 1, R)

Input:

  • The first line of input contains two space separated integer N and Q denoting size of array and number of queries respectively.
  • The second line contains N space separated integers denoting array A.
  • Next Q lines are of one of the following format:
    • 1 ID VAL : for type 1 query
    • 2 L R : for type 2 query

Output:

  • For each type 2 query, output the answer modulo 109+7 in a new line.

Constraints:

  • \(1 \le N,Q \le 10^{5}\)
  • \(1 \le L,R \le N\)
  • \(1 \le VAL \le 10^{9}\)

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:30
134 votes
Tags:
Medium
Points:30
36 votes
Tags:
ApprovedDynamic ProgrammingMediumOpenReadySegment TreesTrees
Points:30
2 votes
Tags:
Binary SearchDSUData StructuresDynamic ProgrammingMediumMerge SortSegment Trees