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

Автор Omarr., история, 15 месяцев назад, По-английски

This is my first blog ( Hopefully not the last :D )

I came across this problem in a group contest that no one could solve (I couldn't solve it either, so i need help) basically all the problem is just given an positive integer n (1 <= n <= 1e5) and array a, your task is to find the number of pairs i, j (1 <= i < j <= n) such that a[i] | a[j] = a[i] or a[i] | a[j] = a[j]. Yes, that's it.

I'd be really grateful for any help. Thanks for your time.

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

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится -40 Проголосовать: не нравится

Here is a solution: start one for loop iterating $$$i$$$ from $$$1$$$ to $$$n$$$ and then start another one iterating $$$j$$$ from $$$i + 1$$$ to $$$n$$$. The reason why we pick $$$i + 1$$$ is so that we don't pick duplicates and we don't count pairs where $$$i = j$$$. Increment your answer by $$$1$$$ if $$$a[i] | a[j] = \max(a[i], a[j])$$$.

»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Just use SOS DP.

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

Instead of counting subsets which is O(3^n), why not use high-dimensional prefix sum, its O(n*2^n) right?

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

nvm thats just sosdp