P3374 "template" Tree array 1
-
- Topic provider Hansbug
- Label
- Difficulty popularization/improvement-
Submit a discussion
Recent discussions
- Incorrect description of the topic
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 and Output Sample input example # #:
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
Just remember that Plus is plus, and it's a minus.
#include <cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespacestd;intN, m,a[500010];voidAddintLintR) { while(L <=N) {a[l]+=R; L+ = L & (-l); }}intSumintx) { intnum =0; while(x) {num+=A[x]; X-= x & (-x); } returnnum;}intMain () {scanf ("%d%d", &n, &m); for(inti =1; I <= N; i++) { intx; scanf ("%d", &x); Add (i, x); } for(inti =1; I <= m; i++) { intA, B, C; scanf ("%d%d%d", &a, &b, &c); if(A = =1) Add (b, c); Elseprintf ("%d\n", sum (c)-sum (b-1)); } //while (1); return 0;}
Rokua P3374 "template" Tree array 1