https://www.luogu.org/problem/show?pid=3368 Topic Description
Title, you need to perform the following two operations, known as a sequence:
1. Add x to each number of intervals
2. Find out the number of a
Input/output format
Input format:
The first line contains two integers n, M, respectively, indicating the number of numbers and the total number of operations.
The second line contains n space-delimited integers, where the I number represents the initial value of item I of a sequence.
The next M line contains 2 or 4 integers, representing an operation, as follows:
Action 1: Format: 1 x y k meaning: Add K to each number in the interval [x, y]
Action 2: Format: 2 x Meaning: output x number of values
Output format:
The output contains several line integers, which is the result of all Operation 2.
Input and Output Sample input example # #:
5 51 5 4 2 31 2 4 22 31 1 5-11 3 5 72 4
Sample # # of output:
610
Description
Time limit: 1000ms,128m
Data size:
For 30% data: n<=8,m<=10
For 70% data: n<=10000,m<=10000
For 100% data: n<=500000,m<=500000
Sample Description:
So the output is 6, 10
1#include <cstdio>2 3 #defineLowbit (x) (x& (×))4 5 using namespacestd;6 7 Const intN500000+ the);8 intN,m,x,y,k,tr[n];9 intIf_,ch,od;Ten OneInlinevoidReadint&x) A { -if_=x=0; Ch=GetChar (); - for(;ch<'0'|| Ch>'9'; ch=GetChar ()) the if(ch=='-') if_=1; - for(; ch>='0'&&ch<='9'; ch=GetChar ()) -x=x*Ten+ch-'0'; - if(if_) x= (~x) +1; + } - +InlinevoidUpintIintx) A { at for(; I<=n;i+=lowbit (i)) tr[i]+=x; - } - -InlineintQueryintx) - { - intret=0; in for(; x;x-=lowbit (x)) ret+=Tr[x]; - returnret; to } + - intMain () the { * read (n); read (m); $ for(intI=1; i<=n;i++)Panax NotoginsengRead (x), Up (i,x-k), k=x; - for(; m;m--) the { + read (OD); A if(od==1) the { + Read (x); Read ( y); Read (k) ; -Up (X,K); Up (y+1,-k); $ } $ Else - { - read (x); theprintf"%d\n", query (x)); - }Wuyi } the return 0; -}
Rokua--p3368 "template" Tree array 2