cswork / OA打开练习工作台

MicrosoftOA #18

Count Subarrays with Bitwise OR Present

估计中等可在线判题

考点(AI 标注)位运算哈希计数

Count the non-empty contiguous subarrays whose bitwise OR of all elements equals some element of the original array (that element does not have to be inside the current subarray). The original site undercounted [1,6,7]; by the definition the answer is 6.

输入格式

This site's input: the first line contains n (1..100000), and the second line contains n positive integers (1..10⁹).

输出格式

Output a single integer, the answer.

样例 1

输入:

3
1 6 7

输出:

6

样例 2

输入:

3
2 4 7

输出:

5

样例 3

输入:

1
1

输出:

1

样例说明

Example 1: the ORs of the three single-element segments, the two segments of length 2, and the whole array all lie in {1,6,7}, so there are 6 segments.

Example 2: only [2,4] has OR=6, which is not in the original array; the other 5 segments are valid.

Example 3: the only subarray has OR 1, so the answer is 1.