Codeforces Round 441 (Div. 1, by Moscow Team Olympiad)
D
High Cry
Codeforces
2200
原题
← CE →
翻译中…

Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)

翻译中…

Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this ridge: if Rick and Morty begin crying simultaneously from different mountains, their cry would be heard between these mountains up to the height equal the bitwise OR of mountains they've climbed and all the mountains between them.

翻译中…

Bitwise OR is a binary operation which is determined the following way. Consider representation of numbers $*x*$ and $*y*$ in binary numeric system (probably with leading zeroes) $*x* = *x*_{*k*}... *x*_{1}*x*_{0}$ and $*y* = *y*_{*k*}... *y*_{1}*y*_{0}$. Then $*z* = *x* | *y*$ is defined following way: $*z* = *z*_{*k*}... *z*_{1}*z*_{0}$, where $*z*_{*i*} = 1$, if $*x*_{*i*} = 1$ or $*y*_{*i*} = 1$, and $*z*_{*i*} = 0$ otherwise. In the other words, digit of bitwise OR of two numbers equals zero if and only if digits at corresponding positions is both numbers equals zero. For example bitwise OR of numbers $10 = 1010_{2}$ and $9 = 1001_{2}$ equals $11 = 1011_{2}$. In programming languages C/C++/Java/Python this operation is defined as «|», and in Pascal as «or».

翻译中…

Help Rick and Morty calculate the number of ways they can select two mountains in such a way that if they start crying from these mountains their cry will be heard above these mountains and all mountains between them. More formally you should find number of pairs $*l*$ and $*r*$ ($1 ≤ *l* < *r* ≤ *n*$) such that bitwise OR of heights of all mountains between $*l*$ and $*r*$ (inclusive) is larger than the height of any mountain at this interval.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($1 ≤ *n* ≤ 200 000$), the number of mountains in the ridge.

翻译中…

Second line contains $*n*$ integers $*a*_{*i*}$ ($0 ≤ *a*_{*i*} ≤ 10^{9}$), the heights of mountains in order they are located in the ridge.

翻译中…

Output

翻译中…

Print the only integer, the number of ways to choose two different mountains.

翻译中…

Note

翻译中…

In the first test case all the ways are pairs of mountains with the numbers (numbering from one):

翻译中…

$(1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)$

翻译中…

In the second test case there are no such pairs because for any pair of mountains the height of cry from them is $3$, and this height is equal to the height of any mountain.

翻译中…

样例

Input #1
5
3 2 1 6 5
Output #1
8
InputCopy OutputCopy
Input #2
4
3 3 3 3
Output #2
0
InputCopy OutputCopy
题目信息
题号
875D
时间限制
1 s
内存限制
512 MB
标签
二分
位运算
组合数学
数据结构
分治

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。