Problem 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 format
The first row of 2 integers n,m.
The next line of n integers represents the initial weights of the n lattices.
Next m line, 3 integers per line p,x,y,p represents the type of operation, p=1 when the weight of the modified lattice X is y,p=2 when the weighted value of the interval [x, y] is calculated, and the p=3 indicates the maximum weight of the interval [x, y] lattice.
Output format
There are several lines, the number of rows equals the total number of p=2 or 3 operations.
1 integers per line, corresponding to the result of each p=2 or 3 operation.
Sample Input 4 3
1 2 3 4
2 1 3
1 4 3
3 1 4 Sample output 6
3 Data size and conventions
For 20% of data n <= 100,m <= 200.
For 50% of data n <= 5000,m <= 5000.
For 100% data 1 <= n <= 100000,m <= 100000,0 <= lattice weights <= 10000.
Example code:
Import Java.util.arraylist;import Java.util.scanner;public class operation lattice {public static int n, m, p, x, y;public static int A Rr[];p ublic static arraylist<integer> list = new arraylist<integer> ();p ublic static void Main (string[] args) {Scanner sc = new Scanner (system.in); n = sc.nextint (); m = Sc.nextint (); arr = new int[n];for (int i=0; i<n; i++) {Arr[i] = Sc.nextint ();} for (int i = 0; i < m; i++) {p = Sc.nextint (); x = Sc.nextint (); y = Sc.nextint (); Operate (P, x, y);} for (int i=0; i<list.size (); i++) {System.out.println (List.get (i));} Sc.close ();} private static void operate (int p, int x, int y) {//system.out.println (P + "," + x + "," + Y "), if (p = = 1) {arr[x-1] = AR R[Y-1];} else if (p = = 2) {int result = 0;for (int i=x-1; i<=y-1; i++) {result + = Arr[i];} List.add (result);} else if (p = = 3) {int max = integer.min_value;for (int i=x-1; i<=y-1; i++) {if (Arr[i] > max) {max = Arr[i];}} List.add (max);}}}
"Blue Bridge Cup" operation Lattice