A11175 | High Cry
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains integer $n$ ( $1<=n<=200000$ ), 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.
Second line contains $n$ integers $a_{i}$ ( $0<=a_{i}<=10^{9}$ ), the heights of mountains in order they are located in the ridge.
输出格式
Print the only integer, the number of ways to choose two different mountains.
输入输出样例
输入 #1
5 3 2 1 6 5
输出 #1
8
输入 #2
4 3 3 3 3
输出 #2
0
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.
$(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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?