-
Total time limit:
-
10000ms
-
Single test point time limit:
-
1000ms
-
Memory Limit:
-
262144kB
-
-
Describe
-
-
to a series of n long, there are m operations, each operation is one of the following two:
(1) Modify a number in the series
(2) To find a continuous paragraph in a series and
-
-
Input
-
-
The first line is two positive integers n and M.
The second row, n integers, represents the sequence.
Next M line, each line begins with a character, if the character is ' M ', it represents a modification operation, the next two integers x and Y, indicating that the value of the X position is modified to Y, if the character is ' Q ', then a query operation, the next two integers x and y, for the [x, Y] interval of the and.
-
-
Output
-
-
output a single line for each query operation, indicating the answer.
-
-
Sample input
-
-
5 to 2 3 4 5Q 1 5M 2 7Q 1 5
-
-
Sample output
-
-
1520
-
-
Tips
-
-
1<=n<=10^5,1<=m<=10^5, the input is guaranteed to be valid, and all integers and answers are available with signed 32-bit integer storage.
-
-
-
- There must be no doubt about the tree-like array,
-
- but this is not a plus or minus, but a direct modification,
-
- However, direct modification will explode zero, the reason for their yy to know.
-
- So, every time we change, we add the difference between the number and the current number, and then we change the current number to the number we're going to change
.
-
-
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intmaxn=100001;6 intA[MAXN];7 intTREE[MAXN];8 intn,m;9 voidReadint&N)Ten { One CharC='+';intx=0;BOOLflag=0; A while(c<'0'|| C>'9') {C=getchar ();if(c=='-') flag=1;} - while(c>='0'&&c<='9') -X= (x<<1) + (x<<3) +c- -, c=GetChar (); theflag==1? n=-x:n=x; - } - intlbintp) - { + return(p) & (-p); - } + voidAddintPosintv) A { at intp=Pos; - while(p<=N) - { -tree[p]+=v; -p+=lb (p); - } in } - intSumintPOS) to { + intans=0; - intp=Pos; the while(P) * { $ans+=Tree[p];Panax Notoginsengp-=lb (p); - } the returnans; + } A intMain () the { + read (n); read (m); - for(intI=1; i<=n;i++) $ { $ intp; - read (p); -a[i]=p; the Add (i,p); - }Wuyi for(intI=1; i<=m;i++) the { - CharCintx, y; WuCin>>c;read (x); Read (y); - if(c=='Q') Aboutprintf"%d\n", sum (y)-sum (X-1)); $ Else - { -Add (x,y-a[x]); -a[x]=y; A } + the } - return 0; $}
10:challenge 3 (tree-like array directly modified)