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

Автор PUSSY_LICKING_LOLI_69, история, 8 месяцев назад, По-английски

Given an array A of size n (n<=150000) and a permutation P. You must do q queries(q<=150000) of 4 types:

1 l r v: A[p[i]]+=v with all l<=i<=r

2 l r: calculate sum of all A[i] with all l<=i<=r

3 x y: swap P[x] and P[y]

4 k: roll back A and P to right before the kth query

Here's the link the the original problem(Vietnamese) if you're interested: https://oj.vnoi.info/problem/olp_sc23_pquery

I'll be looking forward to your answers. Thank you :D

Edit: Apparently someone's accepted solution has square root decomposion as a part of it but I don't have access to their code and any detail on how it works. Can someone expand on this approach?

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

»
8 месяцев назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

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

»
8 месяцев назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

It's not every day that you come across a PUSSY_LICKING_LOLI_69 solving segment tree problems; What a time to be alive! In any case, here's how I would solve it:

Type $$$1$$$ and $$$2$$$ can be handled by a standard lazy segtree.

Type $$$3$$$ can be handled by querying $$$p_x$$$ and $$$p_y$$$, then adding $$$p_y-p_x$$$ to $$$p_x$$$ and $$$p_x-p_y$$$ to $$$p_y$$$.

Type $$$4$$$ can be handled by making the segtree persistent (see tutorial).

»
8 месяцев назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

nice pfp lmao

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

A rather inefficient approach to show that it can be done in polylogarithmic time: Take the inverse of the permutation; then the first query becomes doing A[i] += v for l <= P^-1[i] <= r. Then this becomes maintaining a set of points $$$(i,P^{-1}[i])$$$ which can be done with a 2D segment tree.

I looked at the problem and it doesn't seem to require you to do it online, so you can take it offline and the 4th operation becomes reverting operations -- both operations have easy inverses.

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    What is the time complexity for your approach? Can a 2D segtree handle a (1e5 X 1e5) board, or do we have to make it both dynamic and persistent? Seems like a lot of work...

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

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