Problem Statement

We have a variable \(X\) and \(N\) kinds of operations that change the value of \(X\). Operation \(i\) is represented as a pair of integers \((T_i,A_i)\), and is the following operation:

  • if \(T_i=1\), it replaces the value of \(X\) with \(X\) and \(A_i\);
  • if \(T_i=2\), it replaces the value of \(X\) with \(X\) or \(A_i\);
  • if \(T_i=3\),, it replaces the value of X with X xor \(A_i\).

Initialize \(X\) with the value of \(C\) and execute the following procedures in order:

  • Perform Operation 1, and then print the resulting value of \(X\).
  • Next, perform Operation 1,2 in this order, and then print the value of \(X\).
  • next, perform Operation 1,2,3 in this order, and then print the value of X.

  • Next, perform Operation 1,2,…,N in this order, and then print the value of X.

Constraints

  • \(1≤N≤2×10^5\)
  • \(1≤T_i≤3\)
  • \(0≤A_i<2^{30}\)
  • \(0≤C<2^{30}\)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

\(N\) \(C\)

\(T_1\) \(A_1\)

\(T_2\) \(A_2\)



\(T_N\) \(A_N\)

Output

Print \(N\) lines, as specified in the Problem Statement.

Sample Input 1

3 10
3 3
2 5
1 12

Sample Output 1

9
15
12

The initial value of \(X\) is \(10\).

  • Operation \(1\) changes \(X\) to \(9\).
  • Next, Operation \(1\) changes \(X\) to \(10\), and then Operation \(2\) changes it to \(15\).
  • Next, Operation \(1\) changes X to \(12\), and then Operation \(2\) changes it to \(13\), and then Operation \(3\) changes it to \(12\).

Sample Input 2

9 12
1 1
2 2
3 3
1 4
2 5
3 6
1 7
2 8
3 9

Sample Output 2

0
2
1
0
5
3
3
11
2

为了方便,称执行操作1,2\(\cdots\)为第i轮操作

位运算问题,考虑按位计算。把C拆成每一位,求出他的运算后的答案。这是就只用考虑and,xor,or 0/1

  • xor 0,and 1,or 0可以看作不变,不操作

  • xor 1其实就是取反,可以打上取反标记。

  • and 0=直接赋值为0,取反标记清空,答案直接为0,不管前面有哪些多少操作。

  • or 1=直接赋值为1,同上

但是有很多轮操作,所以我们可以推出第i轮结束时赋值和取反操作情况。如果是没有赋值,那么第i轮结束后这一位答案就是上一轮结束答案^取反操作,否则就直接赋值。注意取反后赋值操作跟着取反。

每一位都这样操作,相加,就求出了答案。

#include<cstdio>
const int N=2e5+5;
int n,c,ans[N],rt,tx,tt,t[N],a[N];
int main()
{
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++)
scanf("%d%d",t+i,a+i);
for(int i=30;~i;i--)
{
tx=0,rt=-1,tt=c>>i&1;//rt:赋值,tx:取反
for(int j=1;j<=n;j++)
{
if(t[j]==1)
if(!(a[j]&1<<i))
rt=tx=0;
if(t[j]==2)
if(a[j]&1<<i)
rt=1,tx=0;
if(t[j]==3)
if(a[j]&1<<i)
tx^=1;
if(rt==-1)
tt=tt^tx;
else
tt=rt^tx;
ans[j]+=tt<<i;
}
}
for(int i=1;i<=n;i++)
printf("%d\n",ans[i]);
}

[ABC261E] Many Operations的更多相关文章

  1. backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

    昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx> ...

  2. HDU 5938 Four Operations(四则运算)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)

    一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...

  4. OpenCascade Modeling Algorithms Boolean Operations

    Modeling Algorithms Boolean Operations of Opencascade eryar@163.com 布尔操作(Boolean Operations)是通过两个形状( ...

  5. A.Kaw矩阵代数初步学习笔记 4. Unary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  6. A.Kaw矩阵代数初步学习笔记 3. Binary Matrix Operations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  7. mouse scrollings and zooming operations in linux & windows are opposite

    mouse scrollings and zooming operations in linux & windows are opposite. windows中, 鼠标滚动的方向是: 查看页 ...

  8. MongoDB—— 写操作 Core MongoDB Operations (CRUD)

    MongoDB使用BSON文件存储在collection中,本文主要介绍MongoDB中的写操作和优化策略. 主要有三种写操作:        Create        Update        ...

  9. MongoDB—— 读操作 Core MongoDB Operations (CRUD)

    本文主要介绍内容:从MongoDB中请求数据的不同的方法 Note:All of the examples in this document use the mongo shell interface ...

  10. [codeforces 339]D. Xenia and Bit Operations

    [codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, con ...

随机推荐

  1. 解放生产力orm并发更新下应该这么处理求求你别再用UpdateById了

    解放生产力orm并发更新下应该这么处理求求你别再用UpdateById了 背景 很多时候为了方便我们都采用实体对象进行前后端的数据交互,然后为了便捷开发我们都会采用DTO对象进行转换为数据库对象,然后 ...

  2. 简单描述下HTTP协议和TCP协议之间的关系以及TCP三次握手, 四次挥手

    TCP 三次握手, 四次挥手 TCP(传输控制协议)是一种用于在计算机网络中建立可靠连接的协议.TCP连接的建立和终止分别使用了"三次握手"和"四次挥手"的过程 ...

  3. API接口技术的使用可以增加软件开发和运行的灵活性,降低软件运行和维护的成本

    随着科技的发展和互联网的普及,越来越多的公司和企业把业务拓展到互联网上,这就需要用到API接口技术.API(Application Programming Interface,应用程序接口)是指不同软 ...

  4. [Python3] 初识py, 一个简单练手的小玩意. 快递查询

    有图有真相 脚本代码 最近刚入门py, 准备写点小玩意练练手. 于是决定拿快递100开刀. 因为它的api很简单. # 快递100 API # 作者: 剑齿虎 # 邮箱: yuxiaobo64@gma ...

  5. Vue源码学习(三):<templete>渲染第二步,创建ast语法树

    好家伙,书接上回   在上一篇Vue源码学习(二):<templete>渲染第一步,模板解析中,我们完成了模板解析 现在我们继续,将模板解析的转换为ast语法树   1.前情提要 代码已开 ...

  6. 月工资不到10元的内容审核专员? - ChatGPT 在内容自动审查中的应用

    内容过滤筛查是指对网络上发布或传播的文本.图片.视频等内容进行审核和监管,以防止出现违法违规.暴力色情.虚假广告.电信诈骗等现象,维护网络安全和社会秩序. 内容过滤筛查是一个亟待解决的问题,因为网络内 ...

  7. 5.0 CRC32校验技术概述

    CRC校验技术是用于检测数据传输或存储过程中是否出现了错误的一种方法,校验算法可以通过计算应用与数据的循环冗余校验(CRC)检验值来检测任何数据损坏.通过运用本校验技术我们可以实现对特定内存区域以及磁 ...

  8. MySQL实战实战系列 04 深入浅出索引(下)

    在上一篇文章中,我和你介绍了 InnoDB 索引的数据结构模型,今天我们再继续聊聊跟 MySQL 索引有关的概念. 在开始这篇文章之前,我们先来看一下这个问题: 在下面这个表 T 中,如果我执行 se ...

  9. SpringSecurity-前后端分离教程

    1.简介 Spring Security 是 Spring 家族中的一个安全管理框架.相比与另外一个安全框架Shiro,它提供了更丰富的功能,社区资源也比Shiro丰富. 一般来说中大型的项目都是使用 ...

  10. code2uml使用教程

    通常的开发顺序是 先设计uml然后进行code编程. 但是很多时候我们是先看到code源码,却不知道uml关系如何. 特别是写论文的时候也是很需要的. 这个code2uml,就是辛苦搜寻到的结果,可以 ...