当前位置:网站首页>XOR prefix and +map maintenance
XOR prefix and +map maintenance
2022-06-13 04:17:00 【csx_ zzh】
give n and n Number , Seek differences or make peace 0 Number of sub segments of
set up a[i] Number entered for
b[i] Is an XOR prefix and
b[i] = a[1] ^ a[2] ^ … ^ a[i - 1] ^ a[i]
A number is known x^y = 0 If and only if x == y It was established
So for a paragraph [1,r] Come on , The XOR prefix and are b[r], So if you want to r Is exclusive or is 0 The right half of the sub segment of , Then you only need a number in front of you b[i] == b[r], that [i + 1,r] This XOR and sum is 0
Like
about x1,x2,x3…xr, If you want to find a range [i,r] Make the exclusive or sum of its intervals be 0, set up x1,x2,x3…xj The exclusive or and are b[j] So if b[j] == b[r], in other words b[j] ^ b[j+1,r] = b[r] And only x ^ y == x If and only if y = 0 It was established .
Then you just need the prefix XOR and +map Maintenance is enough
#include <iostream>
#include <map>
#define ll long long
using namespace std;
const int maxn = 2e5 + 5;
std::map<ll, ll> mp;
ll a[maxn],b[maxn];
int main(){
int n;
cin >> n;
ll ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
b[i] = a[i] ^ b[i - 1];
if(b[i] == 0)ans++;
ans += mp[b[i]];
mp[b[i]]++;
cout << ans << endl;
}
cout << ans << endl;
return 0;
}
边栏推荐
- 高等数学(第七版)同济大学 习题1-2 个人解答
- Single chip microcomputer: pcf8591 application program
- Simple static web page + animation (small case)
- [Yugong series] June 2022 Net architecture class 080 master cluster and database switching of distributed middleware schedulemaster
- On the value of line height
- 120. triangle minimum path sum - Dynamic Planning
- JSTL -- JSP standard tag library
- Single chip microcomputer: d/a output
- Lambda end operation reduce merge
- Solution to failure to download files by wechat scanning QR code
猜你喜欢
Google Chrome browser reports an error: net:: err_ BLOCKED_ BY_ CLIENT
SCM: introduction to Modbus communication protocol
Hugo 博客搭建教程
EMC rectification outline
[test development] use case
Uni app dynamic add style dynamic bind background image invalid
Difference between OKR and KPI
The could not find com scwang. smart:refresh-layout-kernel:2.0.3. Required by: project: the app cannot load the third-party package
[test development] basic concepts related to testing
dumi 搭建文檔型博客
随机推荐
Principle and control program of single chip microcomputer serial port communication
Understand the pseudo static configuration to solve the 404 problem of refreshing the page of the deployment project
1-72 convert string to decimal integer
Filter and listener
Mongodb compass connects to the Alibaba cloud remote server database or reports an error occurred while loading instance info: command hostinfo req
MSG messages in ROS
Single chip microcomputer: basic concepts of a/d and d/a
Redis hyperloglog cardinality statistics algorithm
Big Five personality learning records
Redis数据持久化
高等数学(第七版)同济大学 习题1-3 个人解答
Zoom and move the H5 part of the mobile end
VGA display based on de2-115 platform
Dumi construit un blog documentaire
MCU: pcf8591 hardware interface
[test development] basic concepts related to testing
Detailed explanation of KOA development process
Forgotten fleeting years
Single chip microcomputer: a/d differential input signal
SCM: introduction to Modbus communication protocol