Transmission Door
Algorithm training operation Lattice
Time limit: 1.0s memory limit: 256.0MB 1 brocade sac 2 Jin sac 3 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.
532401 |
[Email protected] |
Operation Lattice |
04-10 10:34 |
1.614KB |
C++ |
That's right |
100 |
312ms |
4.269MB |
Evaluation details |
1#include <iostream>2#include <cstdlib>3#include <cstdio>4#include <algorithm>5#include <cstring>6#include <vector>7#include <queue>8 using namespacestd;9 Ten #definell Long Long One A Const intN =100005; - Constll inf =0x3f3f3f3f; - the intn,m; - intA[n]; - intsum[n*4],ma[n*4]; - + voidBuildintIintLintR) - { + if(l==R) { Asum[i]=ma[i]=A[l]; at return; - } - intMid= (L+R)/2; -Build (i*2, l,mid); -Build (i*2+1, mid+1, R); -Ma[i]=max (ma[i*2],ma[i*2+1]); insum[i]=sum[i*2]+sum[i*2+1]; - return; to } + - voidSetValue (intIintLintRintXinty) the { * if(l==R) { $ma[i]=sum[i]=a[x]=y;Panax Notoginseng return; - } the intMid= (L+R)/2; + if(x<=mid) ASetValue (i*2, l,mid,x,y); the Else +SetValue (i*2+1, mid+1, r,x,y); -Ma[i]=max (ma[i*2],ma[i*2+1]); $sum[i]=sum[i*2]+sum[i*2+1]; $ } - - intQuerysum (intIintLintRintXinty) the { - if(X>r | | y<l) {Wuyi return 0; the } - Else if(X<=l && r<=y) { Wu returnSum[i]; - } About intMid= (L+R)/2; $ intlsum=0, rsum=0; - if(mid>=x) { -Lsum=querysum (i*2, l,mid,x,y); - } A if(mid<y) { +Rsum=querysum (i*2+1, mid+1, r,x,y); the } - returnlsum+rsum; $ } the the intQueryma (intIintLintRintXinty) the { the if(X>r | | y<l) { - return 0; in } the Else if(X<=l && r<=y) { the returnMa[i]; About } the intMid= (L+R)/2; the intLma=0, rma=0; the if(mid>=x) { +Lma=queryma (i*2, l,mid,x,y); - } the if(mid<y) {BayiRma=queryma (i*2+1, mid+1, r,x,y); the } the returnMax (Lma,rma); - } - the intMain () the { the inti; the intp,x,y; - //freopen ("data.in", "R", stdin); thescanf"%d%d",&n,&m); the for(i=1; i<=n;i++){ thescanf"%d",&A[i]); 94 } theBuild1,1, n); the for(i=1; i<=m;i++){ thescanf"%d%d%d",&p,&x,&y);98 if(p==1){ AboutSetValue (1,1, n,x,y); - }101 Else if(p==2){102printf"%d\n", Querysum (1,1, N,x,y));103 }104 Else{ theprintf"%d\n", Queryma (1,1, N,x,y));106 }107 }108 109 return 0; the}
Blue Bridge Cup algorithm training operation lattice [line tree]