LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Segment Sums of a Changing Array

EasyProblem #63
Time LimitMemoryInputOutput
0.5 s64 MBstdinstdout

You are given an array of n integers, and then a list of m operations to carry out on it, in order. Each operation is one of two kinds: it either changes a single element, or asks for the sum of a stretch of consecutive elements.

Write a program that prints the answer to every question, using the array as it stands at that moment.

Input

First line of input will be a single integer t - the number of testcases.
The first line of each testcase contains two integers n and m - the length of the array and the number of operations.
The second line contains n integers a0​,a1​,…,an−1​.
Each of the next m lines contains one operation, in one of two forms:

  • s i v - set the element at position i to v;
  • q l r - query the sum of the elements at positions l,l+1,…,r.

Positions are counted from 0, so i, l and r are all between 0 and n−1.

Output

For every q operation, in the order the operations appear, print on its own line the sum of that stretch.

Example

Input
1
5 5
1 2 3 4 5
q 0 4
q 2 3
s 2 5
s 3 6
q 0 4
Output
15
7
19

The array starts as 1,2,3,4,5, so the whole array sums to 15 and positions 2 to 3 sum to 3+4=7. After the two changes the array is 1,2,5,6,5, which sums to 19.

Constraints

1≤t≤10
1≤n≤105
1≤m≤105
0≤ai​≤10 and 0≤v≤10
0≤i≤n−1 and 0≤l≤r≤n−1
The sum of n over all testcases does not exceed 2⋅105, and so does the sum of m


This problem was adapted, with permission, from Sume segmenata promenljivog niza, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit