AOJ dsl_2_e Range Add Query (RAQ)

Source: Internet
Author: User

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≤stn
    • 1≤in
    • 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.