P3374 "template" tree Array 1 title description
Title, you need to perform the following two operations, known as a sequence:
1. Add a number to the X
2. Find out the amount of each number in a range and
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 3 or 4 integers, representing an operation, as follows:
Action 1: Format: 1 x k Meaning: Add x number plus K
Action 2: Format: 2 x y meaning: the and of each number in the output interval [x, y]
output Format:
The output contains several line integers, which is the result of all Operation 2.
Input/Output sample
Input Sample # #:
5 51 5 4 2 31 1 32 2 51 3-11 4 22 1 4
Sample # # of output:
1416
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:
Therefore, the output results 14, 16
1 ProgramNo;2 var3 N,m,i,t,c,x,y:longint;4E:Array[1..500000] ofLongint;5 6 functionlowbit (apple:longint): Longint;7 begin8Lowbit:=apple and-Apple;9 End;Ten One procedureAdd (x,a:longint); A begin - whileX<=n Do - begin thee[x]:=e[x]+A; -x:=x+lowbit (x); - End; - End; + - functionquery (x:longint): Longint; + begin Aquery:=0; at whileX>0 Do - begin -query:=query+E[x]; -x:=x-lowbit (x); - End; - End; in - begin toAssign (input,'1.in'); Assign (output,'1.out'); + reset (input); rewrite (output); - the readln (n,m); * fori:=1 toN Do $ beginPanax Notoginseng read (t); - Add (i,t); the End; + A fori:=1 toM Do the begin + read (c,x,y); - ifC=1 ThenAdd (x, y) $ ElseWriteln (query (y)-query (X-1)); $ End; - close (input); Close (output); - End.
Luogu P3374 "template" tree-like array 1[Single-point modification-interval query]