CF243A.The Brand New Function
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarpus has a sequence, consisting of n non-negative integers: _a_1, _a_2, ..., a__n.
Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a__l | a__l + 1 | ... | a__r.
Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end.
Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a.
Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or".
Polycarpus 有一个由 n 个非负整数组成的序列:a1,a2,…,an。
我们为序列 a 定义函数 f(l,r)(其中 l,r 为整数,且 1≤l≤r≤n),其含义为对下标从 l 到 r 的所有序列元素执行按位或(bitwise OR)运算。形式化地定义为:
f(l,r)=al∣al+1∣⋯∣ar.
Polycarpus 拿出一张纸,写下了所有满足 1≤l≤r≤n 的 f(l,r) 的值。现在他想知道,最终一共得到了多少个互不相同的值。
请帮助 Polycarpus,计算给定序列 a 对应的所有 f(l,r) 值中不同值的个数。
表达式 x∣y 表示对整数 x 和 y 执行按位或运算。该运算在所有现代编程语言中均存在;例如,在 C++ 和 Java 中记作 |,在 Pascal 中记作 or。
输入格式
The first line contains integer n (1 ≤ n ≤ 105) — the number of elements of sequence a. The second line contains n space-separated integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 106) — the elements of sequence a.
第一行包含一个整数 n(1≤n≤105)—— 序列 a 的元素个数。
第二行包含 n 个用空格分隔的整数 a1,a2,…,an(0≤ai≤106)—— 序列 a 的元素。
输出格式
Print a single integer — the number of distinct values of function f(l, r) for the given sequence a.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
输出一个整数——对于给定序列 a,函数 f(l, r) 的不同取值个数。
请注意,在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流或 %I64d 说明符。
输入输出样例
输入#1
3 1 2 0
输出#1
4
输入#2
10 1 2 3 4 5 6 1 2 9 10
输出#2
11
说明/提示
In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.
在第一个测试用例中,Polycarpus 的纸上将写下 6 个数:f(1, 1) = 1,f(1, 2) = 3,f(1, 3) = 3,f(2, 2) = 2,f(2, 3) = 2,f(3, 3) = 0。其中恰好有 4 个不同的数:0,1,2,3。
输入解题思路,AI测评打分。不知道怎么写?