ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Two dimensional interval tree
Posted by typedef 8 Nov 2009 23:16
Hello.

I have an array of numbers from 1 to N. The order is random. I have to answer a lot(M) of questions like: how many numbers from interval [x, y] bigger than k. I tried to build two-dimensional interval tree: each edge of interval tree has an internal tree. But that tree was too large.

1 <= N, M <= 100000
Memory limit = 64 Mb

Also I tried to build Fenwick tree. But it also needs too much memory: O(N^2).

Please, can you help me to compress an interval tree or Fenwick tree? Or, maybe, there is another way to solve this problem?

Thank you.
Re: Two dimensional interval tree
Posted by [SPbSU ITMO] WiNGeR 9 Nov 2009 03:46
You can store in each node of interval tree sorted list of numbers in corresponding interval. It requires O(n log n) memory and can be built in O(n log n) time (you can merge two sorted lists in linear time). With this tree you can answer queries in O(log^2 n) time using binary search

Edited by author 10.11.2009 02:42
Re: Two dimensional interval tree
Posted by typedef 9 Nov 2009 05:24
Thank you! It really works :)