{-# LANGUAGE FlexibleContexts #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Bits

import qualified Data.ByteString.Char8 as C
import Data.List

-- AOJ DSL_2_B Range Sum Query (RSQ)
main = do
  [n,q] <- get
  cxys <- replicateM q get
  mapM_ print $ sol n cxys

get = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

sol :: Int -> [[Int]] -> [Int]
sol n cxys = reverse $ runST $ initBIT n >>= f cxys []

f :: [[Int]] -> [Int] -> BIT s -> ST s [Int]
f [] rs _ = return rs
f ([0,x,y]:ts) rs b = add x y b >> f ts rs b
f ([1,x,y]:ts) rs b = seg x y b >>= \r -> f ts (r:rs) b

-- | Binary Indexed Tree - Implements mutable binary indexed trees
type BIT s = STUArray s Int Int

-- | Construct a new binary indexed tree on the indexes 1 through n. 
initBIT :: Int -> ST s (BIT s)
initBIT n = newListArray (1,n) $ repeat 0

-- | Compute the sum of all indexes 1 through i, inclusive. Takes O(logn). 
atBIT :: Int -> BIT s -> ST s Int
atBIT i bit = f i 0
  where
  f 0 v = return v
  f i v = f (i-i.&.(-i)) . (+v) =<< readArray bit i

-- | Increment the value at index i. Takes O(logn). 
add :: Int -> Int -> BIT s -> ST s ()
add i v bit = do
  (_, u) <- getBounds bit
  let
    f i = when (i<=u) $ do
      writeArray bit i . (+v) =<< readArray bit i
      f (i+i.&.(-i))
  f i

-- | Compute the segment sum of all indexes [l..r]. Takes O(logn). 
seg :: Int -> Int -> BIT s -> ST s Int
seg l r bit = liftM2 subtract (atBIT (l-1) bit) (atBIT r bit)

-- | Initialize BIT with a list 
mkBIT :: [Int] -> ST s (BIT s)
mkBIT as = do
  bit <- initBIT (length as)
  zipWithM (\i a -> add i a bit) [1..] as
  return bit
