P3368 "template" Tree array 2
-
- Topic provider Hansbug
- Label
- Difficulty popularization/improvement-
Submit a discussion
Recent discussions
- No discussion at the moment
Title 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 3 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
Interval operation, single point query
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intN, m,a[500010];voidAddintXintval) { while(x <=N) {a[x]+=Val; X+ = x & (-x); }}intQueryintx) { inttemp =0; while(x) {temp+=A[x]; X-= x & (-x); } returntemp;}intMain () {scanf ("%d%d", &n, &m); for(inti =1; I <= N; i++) { intx; scanf ("%d", &x); Add (i, x); Add (i+1, -x); } for(inti =1; I <= m; i++) { intID, x, y, K; scanf ("%d", &ID); if(id = =1) {scanf ("%d%d%d", &x, &y, &k); Add (x, k); Add (Y+1, -k); } if(id = =2) {scanf ("%d", &x); printf ("%d\n", query (x)); } } //while (1); return 0;}
Rokua P3368 "template" Tree array 2