Game Code mesh algorithm: Lattice games

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.