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

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

Hello Codeforces — ers,

I have this problem need to solve

Given an array a with N integers (1 <= N <= 500000)

Given Q queries (1 <= Q <= 100000), for each query, we have 2 integers L and R, we have to find the maximum value of a[x] + a[y] + a[z] with sastifies:

. L <= x < y < z <= R . y — x < z — y

Thanks a lot :D

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

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

Persistent segment tree probably. You can find the idea at cp-algo advanced segment tree section.

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

    of course I know Persistent Segment tree, but how to solve it :D :D :D. The main idea ?

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

      Iwo items have to be in the lower half and one in the upper. I guess this would be the idea if its not Im sorry i wasnt able to help

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

      Two queries for the halves amd when the range length is odd you would take the lover half to be even

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

It's obvious that if there exists $$$x < i < y$$$ such that $$$a_i \ge \min(a_x,a_y)$$$, we can replace $$$x$$$ with $$$i$$$(or replace $$$y$$$ with $$$i$$$).

So all the possible $$$(x,y)$$$ satisfies the condition that $$$\min(a_x,a_y) > \max_{x<i<y} a_i$$$.

It can be proved that there exists only $$$O(n)$$$ pairs of legal $$$(x,y)$$$.

And the rest of the problem can be solved with segment tree offline(persistent segment tree is not needed).

You can refer to https://www.luogu.com.cn/problem/P11392.

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

    Oh thank you a lot :D :D :D

    I did not think about posible (x, y) just satisfies min(ax, ay) > max(ai)