P5057 [CQOI2006]简单题 前缀异或差分/树状数组
好思路,好思路。。。
思路:前缀异或差分
提交:1次
题解:区间修改,单点查询,树状数组,如思路$qwq$
#include<cstdio>
#include<iostream>
using namespace std;
#define R register int
#define ull unsigned long long
#define ll long long
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
namespace Fread {
static char B[<<],*S=B,*D=B;
#ifndef JACK
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
#endif
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
if(ch==EOF) return EOF; do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=||ch>=);}
inline void gs(char* s) {
register char ch; while(isempty(ch=getchar()));
do *s++=ch; while(!isempty(ch=getchar()));
}
} using Fread::g; using Fread::gs; namespace Luitaryi {
const int N=;
int n,m;
int c[N];
inline int lbt(int x) {return x&-x;}
inline void add(int pos) {for(;pos<=n;pos+=lbt(pos)) c[pos]^=;}
inline int query(int pos) { R ret=;
for(;pos;pos-=lbt(pos)) ret^=c[pos]; return ret;
}
inline void main() {
n=g(),m=g();
while(m--) {
R op=g(),l,r; if(op&) l=g(),r=g(),add(l),add(r+);
else l=g(),printf("%d\n",query(l));
}
}
}
signed main() {
Luitaryi::main();
return ;
}
2019.07.17
P5057 [CQOI2006]简单题 前缀异或差分/树状数组的更多相关文章
- BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组
BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组 Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加 ...
- [POJ3468]关于整数的简单题 (你想要的)树状数组区间修改区间查询
#include <cstdio> #include <algorithm> #include <cstring> #include <cctype> ...
- 洛谷 P5057 [CQOI2006]简单题 题解
P5057 [CQOI2006]简单题 题目描述 有一个 n 个元素的数组,每个元素初始均为 0.有 m 条指令,要么让其中一段连续序列数字反转--0 变 1,1 变 0(操作 1),要么询问某个元素 ...
- gym102220H 差分+树状数组(区间修改和输出)
这题目很有意思,让我学会了树状数组的差分,更加深刻理解了树状数组 树状数组的差分写法 void add(int x,int k) { for (int i = x;i <= n;i += low ...
- 差分+树状数组【p4868】Preprefix sum
Description 前缀和(prefix sum)\(S_i=\sum_{k=1}^i a_i\). 前前缀和(preprefix sum) 则把\(S_i\)作为原序列再进行前缀和.记再次求得前 ...
- 差分+树状数组 线段树【P2357】 守墓人
题目描述-->p2357 守墓人 敲了一遍线段树,水过. 树状数组分析 主要思路: 差分 简单介绍一下差分(详细概念太麻烦,看下面. 给定一个数组 7 8 6 5 1 8 18 20 35 // ...
- 洛谷 P5057 [CQOI2006]简单题(树状数组)
嗯... 题目链接:https://www.luogu.org/problem/P5057 首先发现这道题中只有0和1,所以肯定与二进制有关.然后发现这道题需要支持区间更改和单点查询操作,所以首先想到 ...
- 洛谷 P5057 [CQOI2006]简单题 (树状数组,位运算)
题意:有一个长度为\(n\)的数组,进行\(m\)次操作,每次读入一个值\(t\),如果\(t=1\),则将区间\([l,r]\)的数字反转,若\(t=2\),则查询下标为\(i\)的值. 题解:树状 ...
- [洛谷P5057][CQOI2006]简单题
题目大意:有一个长度为$n$的$01$串,两个操作: $1\;l\;r:$把区间$[l,r]$翻转($0->1,1->0$) $2\;p:$求第$p$位是什么 题解:维护前缀异或和,树状数 ...
随机推荐
- springboot+mybatis 用redis作二级缓存
1.加入相关依赖包: <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...
- error LNK2001: unresolved external symbol __imp__closesocket@4
环境:Visual C++6.0 问题:链接错误 描述: Linking... NetSrv.obj : error LNK2001: unresolvedexternal symbol __imp_ ...
- LC 1. Two Sum
题目介绍 Given an array of integers, return indices of the two numbers such that they add up to a specif ...
- Snoopy.class.php介绍
Snoopy是一个开源的模拟抓取工具,找到一个不错的介绍网页 记录一下: php开源采集类Snoopy.class.php功能使用介绍与下载地址 Snoopy.class.php使用手册 还有一个介绍 ...
- .Net C# 签名字符串排序
#region Get Sign Content /// <summary> /// Get Sign Content /// </summary> /// <param ...
- Django多对多
表名小写+_set() 得到的是一个QuertSet集合,她的后面可以跟 .add() .remove() .update() .clear() models.py 文件 # 学生表 ...
- 13 Msql之四种事务隔离界别
一.事务的基本要素 1.原子性:事务开始后的所有操作,要么全部做完,要么全部不做,不能停滞在中间环节.事务执行过程中出错,会回滚到事务开始前的状态,所有的操作就像没发生一样.也就是说事务是一个不可分割 ...
- sql 创建新表时的完成格式
1 create table [dbo].[Customer] ( CustomerID int identity(1,1) not null, [Name] [nvarchar](50) null, ...
- 【转】在 Delphi 中创建 Linux 守护程序(服务进程)
转自波哥的译文,必须转过来,太有价值了!原文地址在这里.以下为原文内容: 本文译自 原文链接,语言上做了精炼和排版的变更,以便更简洁明了. Delphi 开始支持 Linux 平台为 Delphi 开 ...
- C#面向对象(五大基本原则 )
五大原则 单一职责原则(SRP)开放封闭原则(OCP) 里氏替换原则(LSP) 依赖倒置原则(DIP) 接口隔离原则(ISP) 一.单一职责原则SRP(Single Responsibility P ...