题目链接

Devendra loves the XOR operation very much which is denoted by ∧ sign in most of the programming languages. He has a list A of N numbers and he wants to know the answers of M queries. Each query will be denoted by three numbers i.e. K,P,R .

For query K,P and R, he has to print the value of the KPRsum which can be described as given below. As the value of the KPRsum can be large. So, print it modulus(109+7).

KPRsum=∑i=PR−1∑j=i+1R(K⊕(A[i]⊕A[j]))

Input Format
The first line contains an integer N, i.e., the number of the elements in the list. List is numbered from 1 to N. 
Next line will contain N space seperated integers. 
Third line will contain a number M i.e. number of queries followed by M lines each containing integers K,P&R.

Output Format
Print M lines, ith line will be answer of ith query. Answer will be 0 in case of P=R.

Constraints
1≤N≤105 
1≤A[i]≤106 
1≤M≤105 
0≤K≤106 
1≤P≤R≤N

Sample Input

3
1 2 3
2
1 1 3
2 1 3

Sample Output

5
4

Explanation

For first query, it will will be

(1⊕(1⊕2))+(1⊕(1⊕3))+(1⊕(2⊕3))=5

话说这题又让我想起了去年南京赛区的一道题目,题目难度属于中等,不过当时是没有想出来。

这题算是那个题目的简单版吧,因为每次只需要选两个数。

题目意思就是:给出一个数列,有m个询问,每次询问给出三个数,k, p, r。

求从数组的区间[p, r]内任意选出两个数a[i], a[j], (i > j),每次得到一个数:k^a[i]^a[j],将其进行累加.

输出最终的和。

Accepted Code:

 #include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const int MOD = 1e9 + ;
const int MAX_N = ;
int a[MAX_N], d[][MAX_N];
int n, m, k, p, r; int main(void) {
ios::sync_with_stdio(false);
cin >> n;
for (int i = ; i <= n; i++) cin >> a[i]; for (int i = ; i < ; i++) {
d[i][] = ;
for (int j = ; j <= n; j++) {
d[i][j] = d[i][j - ] + ((a[j]&(<<i)) ? : );
}
} cin >> m;
while (m--) {
cin >> k >> p >> r;
LL ans = ;
for (int i = ; i < ; i++) {
LL ones = d[i][r] - d[i][p - ];
LL zeros = r - p + - ones;
if ( == (k & (<<i))) ans = (ans + ones * zeros * (<<i)) % MOD;
else ans = (ans + (ones * (ones - ) + zeros * (zeros - )) / * (<<i)) % MOD;
}
cout << ans << endl;
}
return ;
}

最新文章

  1. Rainyday.js – 使用 JavaScript 实现雨滴效果
  2. JAVA插入sql代码
  3. python学习笔记-(五)字符串&amp;字典
  4. SILVERLIGHT&#160;多维表头、复杂表头&#160;MULTIPLE&#160;HEADER
  5. electron小例子
  6. WPF 自定义窗口标题栏
  7. 更有效率的使用 Visual Studio - 快捷键
  8. QT设置前景图位置(配色简单漂亮)
  9. Oracle 重建索引脚本
  10. 批处理获取IP地址
  11. 【转】ethtool 命令详解
  12. Ubuntu的Redis安装
  13. GEETEST极验召集互联网大佬齐聚光谷,共同探讨交互安全问题
  14. python_12 模块
  15. vue.js插入dom节点的方式
  16. 关于zynq7 中MIO的理解
  17. springmvc转换JSON数据
  18. 关于Python的集合set
  19. java浅拷贝和深拷贝
  20. D. Vitya and Strange Lesson Codeforces Round #430 (Div. 2)

热门文章

  1. Matlab神经网络验证码识别
  2. 那些使用VSCode写Python踩过的坑(Anaconda配置)
  3. P3480 [POI2009]KAM-Pebbles
  4. Docker系列(十一):Kubernetes集群集群部署实践
  5. 元素显示v-show
  6. shell脚本实现读取一个文件中的某一列,并进行循环处理
  7. PHP-property_exists()函数
  8. CentOS6安装docker、docker-compose、docker-enter
  9. Chapter 5 查找
  10. ES6之主要知识点(六)数组