# AND QUERIES DECEMBER CIRCUITS

https://www.hackerearth.com/problem/algorithm/submatrix-queries-7e459f97/

can anybody explain how to solve this problem for 100 points?

…It’s not a live contest question.

1 Like

You can check out my solution: https://www.hackerearth.com/submission/22611281/

The short explanation of my solution is to have a dynamic segment tree for each possible value of x (only 0-255). Then for each value x in the array, add it to every segment tree that represents a value whose bit representation is a subset of the bit representation if x. Then for each query use inclusion exclusion on supersets of the desired value in bit representation.

I know this is a quick and dirty explanation. Feel free to ask follow up questions after reading the code.

@benjyamin , can you give the idea on how to solve that 'superior substring ’ question, was stuck on it for days, but never got more than 66 points after all the possible optimization((s)), can you explain the idea/solution ?