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 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
Exercises
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn=500000; typedefLong LongLl;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intN,m,pre;intC[maxn];inlineintLowbit (intx) {returnx&-x;}voidUpdateintXintk) { while(x<=N) {c[x]+=K; X=x+lowbit (x); }}intGetsum (intx) { intans=0; while(x) {ans+=C[x]; X=x-lowbit (x); } returnans;}intMain () {n=read (); m=read (); for(intI=1; i<=n;i++) { intx=read (); Update (I,x-pre); Pre=x; } for(intI=1; i<=m;i++) { intx,y,z,k; Z=read (); if(z==1) {x=read (); Y=read (); k=read (); Update (X,K); Update (Y+1,-k); } if(z==2) {x=read (); printf ("%d\n", Getsum (x)); } } return 0;}
"Valley P3368" "Template" Tree array 2