Lattice Games
Title Description
there are n squares, left-to-right in a row, numbered 1-n.
There are 3 types of operation for m operations:
1. Modify the weights of a lattice,
2. To seek a continuous lattice of weights and
3. Ask for the maximum value of a continuous lattice.
for each of the 2, 3 operation output you have to find the results.
input
Enter the first row of two integers, n for the number of squares, m for the number of operations, N and M in the middle with a space separated;
then enter n lines, one integer per line for the weight of a lattice
then enter M line, each line has three integers, the middle is separated by a space; the first is the selected operation type 1-3, and the second and third integers are the number of the operation lattice.
Sample Input
3 3
7
8
9
2 1 3
3 1 3
2 1 2
Output
no output If 1 operation is performed
outputs an integer if the 2 and 3 operations are performed
Sample Output
-
9
the
This problem is not very difficult, I use Python3 to achieve, to provide you with reference:
1 #Coding:utf82NM = input (). Split (" ")3 #n Lattice m operation Count4n =Int (nm[0])5m = Int (nm[1] )6 7 #enter weights for n squares8boxes = []9 forIinchrange (n):Ten boxes.append (int (input () )) One #the next step is m operation A forIinchRange (m): - #Record Action number -Operation = [Int (i) forIinchInput (). Strip (" "). Split (" ") ] the #Modify weight Input 1 - ifOperation[0] = = 1: -BOXES[OPERATION[1]-1] = operation[2] - Else : +Start = operation[1]-1 -End = Operation[2] + #ask for a weight between a section and input 2 A ifOperation[0] = = 2: at Print(SUM (boxes[start:end])) - #To find the maximum weight value between a period of 3 - elifOperation[0] = = 3: - Print(Max (boxes[Start:end])) - Else: - Pass
Game Code mesh algorithm: Lattice games