CF875D.High Cry
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 = 10102 and 9 = 10012 equals 11 = 10112. 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.
免责声明:俄文版题面中包含大量无法直译的双关语,因此你又多了一个学习俄语的理由 :)
瑞克和莫蒂喜欢去“高喊山脊”(High Cry)大声呼喊——那里有非凡的回声。最近,他们发现了这条山脊一个有趣的声学特性:如果瑞克和莫蒂分别从不同的山峰同时开始呼喊,那么他们的呼喊声将在两座山峰之间、直至等于“他们所攀爬的山峰以及其间所有山峰高度的按位或(bitwise OR)”的高度处被听到。
按位或(bitwise OR)是一种二元运算,其定义如下:考虑数字 x 和 y 在二进制数制下的表示(可能含前导零),即 x=xk…x1x0 与 y=yk…y1y0。则 z=x∣y 定义为 z=zk…z1z0,其中每一位 zi=1 当且仅当 xi=1 或 yi=1;否则 zi=0。换言之,两个数按位或结果的某一位为 0,当且仅当这两个数在该位上均为 0。例如,10=10102 与 9=10012 的按位或结果为 11=10112。在编程语言 C/C++/Java/Python 中,该运算符记作 |,而在 Pascal 中记作 or。
请帮助瑞克和莫蒂计算:他们有多少种方式选择两座山峰,使得若他们分别从这两座山峰开始呼喊,则呼喊声能在这两座山峰及它们之间的所有山峰之上被听到。更形式化地说,你需要找出满足如下条件的数对 (l,r) 的个数(其中 1≤l<r≤n):区间 [l,r](含端点)内所有山峰高度的按位或值,严格大于该区间内任意一座山峰的高度。
输入格式
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 ≤ 109), the heights of mountains in order they are located in the ridge.
第一行包含一个整数 n(1≤n≤200000),表示山脊中山峰的数量。
第二行包含 n 个整数 ai(0≤ai≤109),表示山脊中各山峰按顺序排列的高度。
输出格式
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 开始)为:
(1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)
在第二个测试用例中,不存在满足条件的山对,因为对于任意一对山,它们发出的“哭声”高度均为 3,而该高度恰好等于任意一座山的高度。
输入解题思路,AI测评打分。不知道怎么写?