import           Control.Monad
import           Data.List
import qualified Data.IntMap.Strict            as IntMap
import           Data.IntMap.Strict             ( IntMap )
import           Control.Monad.Trans.State.Strict
import           Data.Maybe

data Query = Update Int Int | Query Int Int Int
data Count = Count Int Int
data SegTree a = SegTree (Int, Int) (SegTree a) (SegTree a) a | Leaf Int a

getQuery :: (Int, [Int]) -> Query
getQuery (i, [l, r]) = Query i l r

sortingKey :: Query -> Int
sortingKey (Update _ prev) = prev
sortingKey (Query _ l _  ) = l

getNextQuery :: Int -> State (IntMap Int, Int) Query
getNextQuery ci = do
  (m, i) <- get
  put (IntMap.insert ci i m, i + 1)
  return $ Update i $ IntMap.findWithDefault 0 ci m

build :: (Int, Int) -> SegTree Int
build (l, r) | l + 1 == r = Leaf l 0
             | otherwise  = SegTree (l, r) (build (l, mid)) (build (mid, r)) 0
  where mid = (l + r) `div` 2

update :: Int -> SegTree Int -> SegTree Int
update _ (Leaf key value) = Leaf key (value + 1)
update key (SegTree (l, r) lt rt value)
  | key < mid = SegTree (l, r) (update key lt) rt (value + 1)
  | otherwise = SegTree (l, r) lt (update key rt) (value + 1)
  where mid = (l + r) `div` 2

count :: (Int, Int) -> SegTree Int -> Int
count a@(l, r) b@(Leaf key value) | l <= key && key < r = value
                                  | otherwise           = 0
count a@(l1, r1) b@(SegTree (l2, r2) lt rt value)
  | r1 <= l2 || r2 <= l1 = 0
  | l1 <= l2 && r2 <= r1 = value
  | otherwise            = count (l1, r1) lt + count (l1, r1) rt

getCount :: Query -> State (SegTree Int) (Maybe Count)
getCount (Update i p) = do
  st <- get
  put $ update i st
  return Nothing
getCount (Query i l r) = do
  st <- get
  return $ Just $ Count i $ count (l, r + 1) st

main :: IO ()
main = do
  [n, q]  <- map read . words <$> getLine
  c       <- map read . words <$> getLine
  queries <-
    map getQuery . zip [1 ..] . map (map read . words) <$> replicateM q getLine
  let allQueries =
        queries ++ evalState (sequence $ map getNextQuery c) (IntMap.empty, 1)
  let counts =
        catMaybes
          $ evalState (sequence $ map getCount $ sortOn sortingKey allQueries)
          $ build (1, n + 1)
  sequence_ $ map (print . (\(Count _ ans) -> ans)) $ sortOn
    (\(Count i _) -> i)
    counts
