与非 乱搞233
来源:互联网 发布:车辆mod修改软件 编辑:程序博客网 时间:2024/06/09 02:15
题目大意:
初始时你有一个空序列,之后有N个操作。
操作分为一下两种:
1. x:在序列末尾插入一个元素x(x=0或1)。
2.LR:定义nand[L,R]为序列第L个元素到第R个元素的与非和,询问nand[L,L]^nand[L,L+1]^nand[L,L+2]^……^nand[L,R]。
Nand就是先与,再取反
f[n]=nand(1,i); sum[n]=
询问时
nand(l,r)=…(!(a[l]&a[l+1])&…)…
f(r)=…(!(f[l]&a[l+1])&…)…
一直往后找就好了..
好像还能二分什么的优化,但我也不会..
有兴趣的读者自己思考…(滑稽)
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#define N 4000005using namespace std;int n,tot,a[N],f[N],sum[N];int query(int l,int r){ int now=l,s=!(a[l]&a[l+1]),ans=a[l]; while(s!=f[now+1]&&now<r){ ans^=s; now++; s=!(s&a[now+1]); } ans^=sum[r]^sum[now]; return ans;}int main(){ scanf("%d",&n); int ans=0; int opt,x,l,r; while(n--){ scanf("%d",&opt); if(opt==1){ scanf("%d",&x); x^=ans; a[++tot]=x; f[tot]=!(f[tot-1]&x); sum[tot]=sum[tot-1]^f[tot]; if(tot==1) f[1]=sum[1]=x; } else{ scanf("%d%d",&l,&r); if(ans==1){l=tot-l+1;r=tot-r+1;swap(l,r);} ans=query(l,r); printf("%d\n",ans); } } return 0;}
阅读全文
0 0
- 与非 乱搞233
- 乱搞
- 乱搞
- 【HDU5656】CA Loves GCD,容斥思想与乱搞
- 与非
- 与非
- qbxt Day 4 乱搞+乱搞+乱搞
- BZOJ4104【乱搞】
- 乱搞题
- 树上乱搞
- 乱搞hash
- 乱搞题
- 代码乱搞
- 乱搞 寿司
- BZOJ4121 乱搞
- 乱搞题目
- [bzoj 1011] [HNOI2008]遥远的行星:近似算法(一种正确性显然的非乱搞的科学做法)
- [乱搞]斐波那契数列与gcd之间一个有趣的定理
- python的入门教程 给大家推荐一下
- Til the Cows Come Home
- ILRuntime第四课Inheritance
- HttpClient4.5.3添加Cookie和Header的User-Agent
- ubuntu安装libtbb.so.2
- 与非 乱搞233
- mysql数据库锁定机制
- mysql 4种插入语句的区别。
- 类型重定义、基类未定义
- There was an error when generating this application with JHipster解决
- linux下mail使用故障mail: command not found
- RocketMQ存储篇——Consumequeue
- Redis教程之一Linux安装Redis
- 组合式控件(购物车数量的加减)