Range ADD Query
Sequence A = { a1,a2 ,..., an }に 's really into expands, の2つの operation うプログラムを as せよ.
- add(s,t,x): as,as+1 ,..., at occupies to x add able.
- get(i): The output of the ai able.
ただし, ai ( i=1,2 ,..., n ) は, 0で early されているものとする.
into force
nqquery1query2:queryq
1 lines occupies A the number of elements n , クエリの number q が and えられる. Yobitsugi bootcut q Line occupies i のクエリ queryi が and えられる. queryiは The following のいずれかの forms で and えられる.
stx
または
i
Each クエリの the first digital は, クエリの species of expands, ' 0 ' が add(s,t,x) , ' 1 ' が get(i) table bamboo Blind.
Output
Each get クエリについて, 1 lines occupies output せよ.
System
- 1≤n≤100000
- 1≤q≤100000
- 1≤s≤t≤n
- 1≤i≤n
- 0≤x≤1000
into force example 1
3 50 1 2 10 2 3 20 3 3 31 21 3
Output Example 1
35
into force Example 2
4 31 20 1 4 11 2
Output Example 2
01
Interval Plus single point check
Tree array + differential or segment tree
Constant, continue to hit the list
1#include <cstdio>2#include <cstdlib>3 4 #defineSiz 100000005 6 CharBuf[siz], *bit =buf;7 8InlineintNextint (void) {9RegisterintRET =0;TenRegisterintNeg =false; One A for(; *bit <'0'; ++bit) - if(*bit = ='-') Neg ^=true; - the for(; *bit >='0'; ++bit) -RET = RET *Ten+ *bit-'0'; - - returnNeg? -Ret:ret; + } - + intN, M; A at intpre[100005]; - -InlineintAskintp) { - intRET =0; - for(p; p-= p&-p) -RET + =Pre[p]; in returnret; - } to +InlinevoidAddintPintk) { - for(; P <= n; p + = p&-p) thePRE[P] + =K; * } $ Panax NotoginsengSigned Main (void) { -Fread (BUF,1, Siz, stdin); the +n =nextint (); Am =nextint (); the + for(inti =1; I <= m; ++i) { - intc =nextint (); $ if(c)//get (i) $printf"%d\n", Ask (Nextint ())); - Else //Add (S, t, x) - { the intx =nextint (); - inty =nextint ();Wuyi intK =nextint (); theAdd (x, k); Add (y +1, -k); - } Wu } - About //System ("pause"); $}
@Author: Yousiki
AOJ dsl_2_e Range Add Query (RAQ)