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

Автор 404Error, 10 лет назад, По-английски

Query problems involving calculating GCD or LCM in a range?

How can we solve this kind of problem efficiently? Does any other data structure also helps in solving these kinds of problems? Some hints might be helpful. Even links to blog or papers. Thanks.

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

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

Well, I believe segment tree can handle all associative operations (but some only with point update. As GCD and LCM are associative you can write a simple segment tree and replace your query operation (min/max, sum, ...) with GCD or LCM.

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

BTW I have just started learning segment tree , BIT, Treap and Splay and so was curious to know how it helps so much. For some people its looks stupid question. No need to downvote, If you want to remove it from recent action, then you can tell me i will remove it depending on the request priority.