Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

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

Please help me in solving this problem. There is no editorial available for this problem.

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

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

Someone please help.

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

It is solved with segment tree. You go through the array and keep the segment tree where for every number you store the length of the longest such sequence that ends on such number. When you handle new array element, you just have to take maximum on [a[i] — k, a[i] + k] plus one and update the value for a[i] in the segment tree.