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

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

We have got N number, from 1 to N. There are 2 types of query:

  1. move number from index i to index j
  2. write what number is at index i

ex.

(0,1,2,3,4);

2 ? -> 2

(0,1,3,4,2); <- from 2 to 4

(0,4,1,3,2); <- from 3 to 1

3 ? -> 3

4 ? -> 2

(0,4,1,3,2); <- from 1 to 1

0 ? -> 0

1 ? -> 4

2 < N < 10 000 000 M < 500 000

I tried with the sqrt-decomposition but not fast enough.. any ideas? http://cms.di.unipi.it/#/task/vasi2/statement

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

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

this problem can be solved using bit or segment tree. can u share link to the problem so that I can test my idea and then discuss wid u.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

If M is the number of queries you could try coordinate compression: instead of keeping track of all numbers keep track of those that appear in the queries.

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

I solved this problem using a modified AVL tree.

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

The link for the problem is http://cms.di.unipi.it/#/task/vasi2/statement . The description is in italian

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

I think some straightforward-like solution with a BST might do well. The only improvement (O((M + N)logN)  →  O(MlogM)) I can think of is to store not single elements but ranges of consecutive elements. For example, in the very beginning you have a BST with only one node which represents the range 1... N. While updating you find the range which has the i-th element and split it into no more than three (that is, you delete it and insert several new).

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

Treap