Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя arshad2117

Автор arshad2117, история, 7 лет назад, По-английски

Given an array A of n elements and queries of type (l r k),find the number of occurrences of k in the range l to r

If there are no updates, we can solve the problem by having a map<int,vector> and doing a binary search.

But what if there are updates involved.

I read somewhere that we can use bit..

But I am not sure how that would be useful

Thank you in advance

  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by arshad2117 (previous revision, new revision, compare).

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

You can use SQRT decomposition. Time complexity is O(q*sqrt(n)*lg(n)+n*lg(n)).

You can also do it offline and compress the numbers in queries, and the time complexity would be O(q*sqrt(n)+n).

»
7 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

You can use de merge sorte tree, that is, a segmente tree where each node is a sorted vector(from l to r), the in each query you just do a lower bound an a upper bound. https://discuss.codechef.com/questions/94448/merge-sort-tree-tutorial

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +45 Проголосовать: не нравится

You can do update and query in , using map<int, Tree>, where Tree is Treap/AVL/Red-black/... tree.