Array range queries — change all occurances of number x to y in range [l,r] of an array

Правка en1, от Cristiano07, 2022-03-22 08:27:57

Hi, I was doing this problem https://mirror.codeforces.com/contest/1620/problem/E and have some questions about the more general version of this problem: Given an array of n elements, we are given q numebr of queries: l r x y — change all occurances of number 'x' to 'y' in the [l,r] segment of the array. Lastly, we want to print all elements of the array after these queries. Constraints: n,q <= 200000. TL 1 second, ML 256 MB. I know there is a solution using DSU-on-tree, but is there a segment trees/lazy propagation approach to this problem that is efficient enough to fit in the time limit? This was my first intuitive approach (since the problem involves range updates) but I couldn't seem to find a way with it.

Теги segment tree, lazy propagation, dsu on tree

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Cristiano07 2022-03-22 08:27:57 812 Initial revision (published)