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

Автор se_crack1122, 3 года назад, По-английски
first question 
given an array a[] of size n and we are asked q queries and there will be 3 types of queries
1 l r for each i in l <= i <= r ai = ai/d where d is the smallest prime factor of ai
2 l r print the sum of all ai with l <= i <= r
3 i k set ai = k

constraints:
1 <= n <= 2e5
1 <= q <= 1e5
1 <= ai , k <= 1e6

sample test case:
5 3
10 2 8 7 6
2 1 4
1 1 4
2 1 4


second ques:
I have attached the images of the second ques

 First part  Second part Third part

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

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

In Q1, first query doesn't make any sense, can you recheck once, i believe there is a typo?

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

Q1: any ai <= 1e6 can have at most 7 prime factors. So you can manually iterate and divide them (you'll need a seg_tree of course, to answer type 2 queries). Type 3 ops doesn't cause problems cuz they are point update ops and for each such update you'll have to divide it by 7 more times. You can see that each cell in the array will be visited not more than 7*(no. of type 3 queries + 1). Q2: Binary lifting + binary search.

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

In first problem, any element will become 1 after 15-20 operations, so, just do brute force, put all indices from 0 to n — 1 in a set, for update query traverse all indices in the range and do the operation, if some element becomes 1 then remove from set, and put the updated values in segtree, number of updates is bounded overall, for sum query the segtree, 3rd is just adding index back to set if it's not 1 and update segtree.