当前位置:网站首页>Leetcode 1310. Subarray XOR query prefix and + XOR
Leetcode 1310. Subarray XOR query prefix and + XOR
2022-06-09 02:40:00 【Confident little screw】
Original link :Leetcode 1310. Subarray XOR query 

The main idea is a ^ b ^b=a
class Solution {
public:
vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {
int n=arr.size();
vector<int> sum(n+1,0);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]^arr[i-1];
vector<int> res;
for(int i=0;i<queries.size();i++)
{
int l=queries[i][0]+1,r=queries[i][1]+1;
res.push_back(sum[r]^sum[l-1]);
}
return res;
}
};
边栏推荐
- Greedy method / Huffman code
- 20. Class E power amplifier design for ads usage record (Part 1)
- 杰理最后io_key 双按键如何使用?【篇】
- 动态规划/n的k拆分 n的最大加数k拆分
- The high-end is weak. Can Yanghe still keep the third place in the industry?
- Tiflash source code reading (III) design and implementation analysis of tiflash deltatree storage engine - Part 1
- Blue Bridge Cup_ Diophantine equation
- Jerry's SPI slave [chapter]
- Jedis tool class, adapting to a single redis and redis cluster
- vins estimator ProcessImage
猜你喜欢

【编码推流】SRS流媒体服务器安装及使用

Unity中,继承MonoBehaviour游戏对象的生命周期

The 600 yuan Tiktok cloud bouncing Di live studio project is the source code of the tuyere project that rewards the income from live broadcasting

Redis data storage

Blue Bridge Cup_ N-ary linear equations_ Gauss elimination

Navicat tool batch imports JSON format data to Doris

【网络协议】| 【01】网络字节序大端、小端

Docker安装Redis

Deux facteurs importants affectant la défaillance de togglerowselection ()

C#中的反射原理及应用
随机推荐
Processes and threads
Embracing out of hospital prescription drugs, Internet medicine should also "get rid of virtual reality"?
Calendar time operation
Range of acwing 789 numbers
TypeScript 基础类型 —— 类型断言
数字电路加法器 基本原理(一)
杰理之如何修改 ad_key 连接的引脚?【篇】
How does Jerry's SPI host configure the driver? [chapter]
Exploration and best practice of automatic verification of object acquisition technology
toggleRowSelection()失效的2个重要影响因素
Common commands for detecting Huawei network devices
贪心法/非01背包问题
pkg-config --modversion opencvPackage opencv was not found in the pkg-config search path. Perhaps y
价值600的抖音云蹦迪直播间项目,靠直播打赏收益的风口项目源码
飞书要不要做生态?剖析第一家 All in 飞书的独立 SaaS 案例
Karmada v1.2 release: open a new era of full-text search
Jerry last IO_ Key how to use double keys? [chapter]
Deux facteurs importants affectant la défaillance de togglerowselection ()
Export related knowledge
export相關知識