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

Maximum of a Changing Segment

EasyProblem #62
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

A weather service keeps n sensors in a row along a mountain road, numbered 0 to n−1, and every sensor reports one temperature.

Two things happen during the day, over and over:

  • a forecaster asks for the highest temperature reported by the sensors on some stretch of road,
  • a sensor is recalibrated and its reading is replaced by a new one.

Write a program that answers every question, using the readings as they are 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 q - the number of sensors and the number of events.
The second line contains n integers v0​,v1​,…,vn−1​ - the readings the sensors start with.
Each of the next q lines describes one event, in one of two forms:

  • a l r - print the highest reading among sensors l,l+1,…,r;
  • b i x - sensor i is recalibrated, its reading becomes x.

Sensors are numbered from 0, so l, r and i are all between 0 and n−1.

Output

For every event of type a, in the order the events appear, print on its own line the highest reading on that stretch.

Example

Input
2
6 6
3 1 4 1 5 9
a 0 5
a 1 3
b 2 7
a 1 3
b 5 -2
a 0 5
1 3
-5
a 0 0
b 0 10
a 0 0
Output
9
4
7
7
-5
10

In the first testcase the readings start as 3,1,4,1,5,9. The whole row peaks at 9, and sensors 1 to 3 hold 1,4,1, so their highest is 4. Sensor 2 is then recalibrated to 7, which makes the same question answer 7. Finally sensor 5 drops to −2, the row becomes 3,1,7,1,5,−2, and its highest is 7.

Constraints

1≤t≤10
1≤n≤105
1≤q≤105
−109≤vi​,x≤109
0≤l≤r≤n−1 and 0≤i≤n−1
The sum of n over all testcases does not exceed 2⋅105, and so does the sum of q

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit