[洛谷P5057][CQOI2006]简单题
题目大意:有一个长度为$n$的$01$串,两个操作:
- $1\;l\;r:$把区间$[l,r]$翻转($0->1,1->0$)
- $2\;p:$求第$p$位是什么
题解:维护前缀异或和,树状数组即可
卡点:无
C++ Code:
#include <cstdio>
#include <cctype> namespace std {
struct istream {
#define M (1 << 24 | 3)
char buf[M], *ch = buf - 1;
inline istream() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
fread(buf, 1, M, stdin);
}
inline istream& operator >> (int &x) {
while (isspace(*++ch));
for (x = *ch & 15; isdigit(*++ch); ) x = x * 10 + (*ch & 15);
return *this;
}
#undef M
} cin;
struct ostream {
#define M (1 << 24 | 3)
char buf[M], *ch = buf - 1;
int w;
inline ostream& operator << (int x) {
if (!x) {
*++ch = '0';
return *this;
}
for (w = 1; w <= x; w *= 10);
for (w /= 10; w; w /= 10) *++ch = (x / w) ^ 48, x %= w;
return *this;
}
inline ostream& operator << (const char x) {*++ch = x; return *this;}
inline ostream& operator << (const char *x) {
while (*x) *this << *x++;
return *this;
}
inline ~ostream() {
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
#endif
fwrite(buf, 1, ch - buf + 1, stdout);
}
#undef M
} cout;
} #define maxn 100010 int n, m;
namespace BIT {
int Tr[maxn], res;
inline void add(int p) {for (; p <= n; p += p & -p) Tr[p] ^= 1;}
inline int ask(int p) {for (res = 0; p; p &= p - 1) res ^= Tr[p]; return res;}
} int main() {
std::cin >> n >> m;
while (m --> 0) {
int op, l, r;
std::cin >> op >> l;
if (op == 1) {
std::cin >> r;
BIT::add(l), BIT::add(r + 1);
} else std::cout << BIT::ask(l) << '\n';
}
return 0;
}
[洛谷P5057][CQOI2006]简单题的更多相关文章
- 洛谷 P5057 [CQOI2006]简单题 题解
P5057 [CQOI2006]简单题 题目描述 有一个 n 个元素的数组,每个元素初始均为 0.有 m 条指令,要么让其中一段连续序列数字反转--0 变 1,1 变 0(操作 1),要么询问某个元素 ...
- 洛谷P5057 [CQOI2006]简单题(线段树)
题意 题目链接 Sol 紫色的线段树板子题??... #include<iostream> #include<cstdio> #include<cmath> usi ...
- 洛谷 P5057 [CQOI2006]简单题(树状数组)
嗯... 题目链接:https://www.luogu.org/problem/P5057 首先发现这道题中只有0和1,所以肯定与二进制有关.然后发现这道题需要支持区间更改和单点查询操作,所以首先想到 ...
- 洛谷 P5057 [CQOI2006]简单题 (树状数组,位运算)
题意:有一个长度为\(n\)的数组,进行\(m\)次操作,每次读入一个值\(t\),如果\(t=1\),则将区间\([l,r]\)的数字反转,若\(t=2\),则查询下标为\(i\)的值. 题解:树状 ...
- P5057 [CQOI2006]简单题(线段树)
果然简单题,5分钟紫题++ 代码 #include <cstdio> #include <algorithm> #include <cstring> using n ...
- 【洛谷P4148】简单题(kd-tree)
传送门 题意: 给出一个\(n*n\)的棋盘,现在有两种操作:一种是某个格子里的数字加上\(A\),另一种是询问矩阵和. 空间限制:\(20MB\),强制在线. 思路: 直接\(kd-tree\)来搞 ...
- P5057 [CQOI2006]简单题
题目描述 有一个 n 个元素的数组,每个元素初始均为 0.有 m 条指令,要么让其中一段连续序列数字反转——0 变 1,1 变 0(操作 1),要么询问某个元素的值(操作 2). 例如当 n = 20 ...
- P5057 [CQOI2006]简单题 前缀异或差分/树状数组
好思路,好思路... 思路:前缀异或差分 提交:1次 题解:区间修改,单点查询,树状数组,如思路$qwq$ #include<cstdio> #include<iostream> ...
- P5057 【[CQOI2006]简单题】
洛谷P5057[CQOI2006]简单题 差分 树状数组基本操作不说了,主要想记录一下异或下的差分 a数组为每一位的真实值(假设\(a[0]=0\)),t为差分后的数组 则\(t[i]=a[i]\)^ ...
随机推荐
- (AOSP)repo checkout指定版本
aosp 怎么切换分支? To properly switch Android version, all you need to change is branch for your manifest ...
- java.lang.RuntimeException: HRegionServer Aborted
java.lang.RuntimeException: HRegionServer Aborted 当我们启动hbase集群的时候,刚启动时每个节点上的进程都显示正常,过一会其他两个节点上的HRegi ...
- CentOS下安装Tomcat环境
一.安装JAVA环境 1.安装JAVA mkdir -p /usr/local/java 下载jdk1.7.0_67.tar.gz包,并解压到 tar xf jdk1.7.0_67.tar.gz -C ...
- VIM第七版
ZZ:退出并保存 e!:退回到上次保存时的样子 cw:修改单词(自动进入插入模式) cc:修改一整行的内容 cs:修改一个词(自动进入插入模式) .:可以重复上一个命令 J:将下一行内容合并到本行末尾 ...
- 使用Python访问HDFS
最近接触到大数据,对于Skpark和Hadoop的料及都停留在第一次听到这个名词时去搜一把看看大概介绍免得跟不上时代的层次. 在实际读了点别人的代码,又自己写了一些之后,虽然谈不上理解加深,至少对于大 ...
- 怎样从Java转换到Kotlin代码:现在就开始使用Kotlin(KAD 29)
作者:Antonio Leiva 时间:Jul, 4, 2017 原文链接:https://antonioleiva.com/kotlin-from-java/ Kotlin最神奇特性之一是它能与Ja ...
- ortp代码简析
ortp初始化 /** * Initialize the oRTP library. You should call this function first before using * ...
- JVM学习--jvm监控和故障处理工具
java虚拟机性能监控常用命令 Sun JDK监控和故障处理命令有jps.jstat.jinfo.jmap.jhat.jstack . 1.jps jps:JVM Process Status Too ...
- MR execution in YARN
Overview YARN provides API not for application developers but for the great developers working on ne ...
- 怎么用js精确判断li已经在ul存在过了?
<ul class="memory_messagelist" id="memory_messagelist"> <li><span ...