c - Find minimum at each index after queries -


suppose given array of known length n initialized infinity.

queries of form (l,r,val) activated such 0 <= l <= r <= n-1. each query updates array such

for in [l, r]   array[i] = min(val, array[i]) 

for example:

initialization: n = 5 - array {inf, inf, inf, inf, inf}

query 1: (1, 3, 6) - array converted {inf, 6, 6, 6, inf}.
query 2: (2, 4, 2) - array converted {inf, 6, 2, 2, 2}.

requirement: after queries, find value @ each element index.

considering above array name of arr then- arr[0] = inf ,arr[1] = 6, arr[2] = 2...

to tackle question, have following ideas:

  1. brute force approach (take each query , update array).

  2. segment tree (with or without lazy propagation).

is there other way solve problem (like of sqrt decomposition or using other data structure, stack or queue) solve linearly or better complexity.

yes, can solve problem in way.
event structure consist boolean start/finish, value , coordinate every query transform in 2 events. example query l:1 r:5 val: 10 transform in event true 10 1 , event false 10 5 sort events coordinate value next go through events , maintain current minimum , fill array can maintain minimum lot of different data structures( example can use map in cpp)

complexity of solution o(m log m+(n+m) log m) m number of queries , n number of elements


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -