题目大意:有一个长度为$n$的$01$串,两个操作:

  1. $1\;l\;r:$把区间$[l,r]$翻转($0->1,1->0$)
  2. $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]简单题的更多相关文章

  1. 洛谷 P5057 [CQOI2006]简单题 题解

    P5057 [CQOI2006]简单题 题目描述 有一个 n 个元素的数组,每个元素初始均为 0.有 m 条指令,要么让其中一段连续序列数字反转--0 变 1,1 变 0(操作 1),要么询问某个元素 ...

  2. 洛谷P5057 [CQOI2006]简单题(线段树)

    题意 题目链接 Sol 紫色的线段树板子题??... #include<iostream> #include<cstdio> #include<cmath> usi ...

  3. 洛谷 P5057 [CQOI2006]简单题(树状数组)

    嗯... 题目链接:https://www.luogu.org/problem/P5057 首先发现这道题中只有0和1,所以肯定与二进制有关.然后发现这道题需要支持区间更改和单点查询操作,所以首先想到 ...

  4. 洛谷 P5057 [CQOI2006]简单题 (树状数组,位运算)

    题意:有一个长度为\(n\)的数组,进行\(m\)次操作,每次读入一个值\(t\),如果\(t=1\),则将区间\([l,r]\)的数字反转,若\(t=2\),则查询下标为\(i\)的值. 题解:树状 ...

  5. P5057 [CQOI2006]简单题(线段树)

    果然简单题,5分钟紫题++ 代码 #include <cstdio> #include <algorithm> #include <cstring> using n ...

  6. 【洛谷P4148】简单题(kd-tree)

    传送门 题意: 给出一个\(n*n\)的棋盘,现在有两种操作:一种是某个格子里的数字加上\(A\),另一种是询问矩阵和. 空间限制:\(20MB\),强制在线. 思路: 直接\(kd-tree\)来搞 ...

  7. P5057 [CQOI2006]简单题

    题目描述 有一个 n 个元素的数组,每个元素初始均为 0.有 m 条指令,要么让其中一段连续序列数字反转——0 变 1,1 变 0(操作 1),要么询问某个元素的值(操作 2). 例如当 n = 20 ...

  8. P5057 [CQOI2006]简单题 前缀异或差分/树状数组

    好思路,好思路... 思路:前缀异或差分 提交:1次 题解:区间修改,单点查询,树状数组,如思路$qwq$ #include<cstdio> #include<iostream> ...

  9. P5057 【[CQOI2006]简单题】

    洛谷P5057[CQOI2006]简单题 差分 树状数组基本操作不说了,主要想记录一下异或下的差分 a数组为每一位的真实值(假设\(a[0]=0\)),t为差分后的数组 则\(t[i]=a[i]\)^ ...

随机推荐

  1. Python中安装Prophet

    1. 先安装pystan依赖 按照https://pystan.readthedocs.io/en/latest/windows.html说明,请使用如下命令 conda install libpyt ...

  2. java 的原型模式和clone

    原型模式是一种创建型设计模式,在java中可以直接调用object.clone(). 原型模式属于对象的创建模式.通过给出一个原型对象来指明所有创建的对象的类型,然后用复制这个原型对象的办法创建出更多 ...

  3. Ubuntu16.04比较好的一系列软件安装介绍

    https://blog.csdn.net/Gerald_Jones/article/details/80784976

  4. Windows10系统,安装appium之坑

    本文主要讲述如何在 Windows10 系统上通过 npm 命令行安装 appium 应该有很多小伙伴在使用cnpm安装appium时遇到过各种报错,比如这样: 相信很多的小伙伴都会遇到这样的报错,导 ...

  5. DEDEcms调用当前栏目顶级栏目url地址

    include/common.func.php 找到这个文件 在文件最下方加入以下代码: //获取顶级栏目url function GetTopTypeurl($id) { global $dsql; ...

  6. 【wx:for】小程序列表渲染的使用说明

    wx:for 控制属性绑定一个数组,即可使用数组中各项的数据重复渲染该组件. 默认数组的当前项的下标变量名默认为 index,数组当前项的变量名默认为 item,即: {{index}} . {{it ...

  7. JVM学习--jvm监控和故障处理工具

    java虚拟机性能监控常用命令 Sun JDK监控和故障处理命令有jps.jstat.jinfo.jmap.jhat.jstack . 1.jps jps:JVM Process Status Too ...

  8. MarkDown编辑器使用

    有几款好用的MarkDown编辑器,参考: https://blog.csdn.net/bat67/article/details/72804251 我就下载的是 MarkDown 2来使用. 现用现 ...

  9. 使用Python进行AES加密和解密

    摘录于:http://blog.csdn.net/nurke/article/details/77267081 另外参考:http://www.cnblogs.com/kaituorensheng/p ...

  10. Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题

    . 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/19698511 . 最近遇到了一系列的屏幕适配问题, 以及 ...