Approach required.

Any help would do…

I’ll check your code later…meanwhile…here is my short solution:—>

1)After some particular ‘k’, values will just keep repeating, you can that out by using the modulo operator,

2)For any, element, answer after ‘k’ rounds is :—> current element&(k-elements in left and k-elements in right), so do a range query for each element .

3)Make sure you make a cyclic segment tree, I mean this cyclic concept means just extending your array from size ‘n’ till it reaches ‘n-1’ again

4)Example Problems(for cyclic stuff in array) :–> https://www.codechef.com/problems/CIRMERGE

https://codeforces.com/contest/1208/problem/B

if k > n then all elements become a[0]&a[1]&…a[n-1]

for other values of k implement a seg tree

If k>n/2… You may want to edit!!

agreed …

1 Like