{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE UnboxedTuples #-}
module Main (main) where
import Data.Int (Int32)
import Control.Monad
import Control.Applicative
import Data.Monoid
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as B8

newtype Min = Min {fromMin :: Int32 } deriving (Ord,Show,Eq,Read)
instance Monoid Min where
  mempty = Min maxBound
  {-# INLINE mempty #-}
  mappend = min
  {-# INLINE mappend #-}

newtype Max = Max Int deriving (Ord,Show,Eq)
instance Monoid Max where
  mempty = Max minBound
  {-# INLINE mempty #-}
  mappend = max
  {-# INLINE mappend #-}

getInts :: IO [Int]
getInts =  map (fst . fromJust . B8.readInt) . B8.words <$> B8.getLine

main :: IO ()
main = do
  n:q:_ <- getInts
  let bst = fromList $ replicate n mempty :: STree (Sum Int)
  loop bst q
  return ()
  where
    loop _ 0 = return ()
    loop !tree !cnt = do
      --print tree
      q:x:y:_ <- getInts
      if q == 0
        then do
        let tree' = add tree x (fromIntegral y)
        loop tree' (cnt-1)
        else do
        print . getSum $ query tree (x,y)
        loop tree (cnt-1)
data STree v = Leaf Int v
             | Branch (Int,Int) v (STree v) (STree v)

range :: STree v-> (Int,Int)
range !(Leaf r _) = (r,r)
range !(Branch r _ _ _) = r
{-# INLINE range #-}

val :: STree v -> v
val !(Leaf _ v) = v
val !(Branch _ v _ _) = v
{-# INLINE val #-}

left,right :: STree v -> Int
left (Main.range -> (fst,_))= fst
right (Main.range -> (_,snd))= snd
{-#INLINE left  #-}
{-#INLINE right #-}

-- 1 始まりの SegTree を作る
fromList :: Monoid v => [v] -> STree v
fromList !xs = makeTree 1 (length xs) xs
{-# INLINE fromList #-}

makeTree :: Monoid v => Int -> Int -> [v] -> STree v
makeTree !l !r !es = loop $ map (uncurry f) (zip [l..r] es)
  where
    loop ![x] = x
    loop !xs = loop $ buildTree xs
    f :: Int -> v -> STree v
    f !ix !v = Leaf ix v
    buildTree !(a:b:ys) = let v = val a `mappend` val b
                          in Branch (left a,right b) v a b : buildTree ys
    buildTree !x = x
{-# SPECIALIZE INLINE makeTree :: Int -> Int -> [Min] -> STree Min #-}

query :: Monoid v => STree v -> (Int, Int) -> v
query !t (ls,rs) = loop t
  where
    loop (Leaf ix v)
      = if ls <= ix && ix <= rs then v else mempty
    loop (Branch (leftist,rightist) v lt rt)
      | rightist < ls || rs < leftist = mempty
      | ls <= leftist && rightist <= rs = v
      | otherwise = loop lt `mappend` loop rt
{-# SPECIALIZE INLINE query :: STree Min -> (Int,Int) -> Min #-}

add :: Monoid v => STree v -> Int -> v -> STree v
add !tree !ix !v = case tree of
  Leaf i v0 -> if ix == i
              then Leaf i (v `mappend` v0)
              else tree
  Branch rng _ l@(Main.range -> (ll,lr)) r
    | ll <= ix && ix <= lr
      -> let l' = add l ix v
         in Branch rng (val l' `mappend` val r) l' r
    | otherwise
      -> let r' = add r ix v
         in Branch rng (val l `mappend` val r') l r'

update :: Monoid v => STree v -> Int -> v -> STree v
update !tree !ix !v = case tree of
  Leaf i _ -> if ix == i
              then Leaf i v
              else tree
  Branch rng _ l@(Main.range -> (ll,lr)) r
    | ll <= ix && ix <= lr
      -> let l' = update l ix v
         in Branch rng (val l' `mappend` val r) l' r
    | otherwise
      -> let r' = update r ix v
         in Branch rng (val l `mappend` val r') l r'
{-# SPECIALIZE INLINE
    update :: STree Min -> Int -> Min -> STree Min #-}
{-# SPECIALIZE INLINE
    update :: STree Max -> Int -> Max -> STree Max #-}
{-# SPECIALIZE INLINE
    update :: Num a => STree (Sum a)-> Int -> Sum a -> STree (Sum a) #-}
{-# SPECIALIZE INLINE
    update :: Num a => STree (Product a)-> Int -> Product a -> STree (Product a) #-}

Measured memory_bytes: 41988