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. AI绘画StableDiffusion美女实操教程:斗破苍穹-小医仙

    之前分享过StableDiffusion的入门到精通教程:AI绘画:Stable Diffusion 终极炼丹宝典:从入门到精通 但是还有人就问:安装是安装好了,可是为什么生成的图片和你生成的图片差距 ...

  2. Python 基础面试第三弹

    1. 获取当前目录下所有文件名 import os def get_all_files(directory): file_list = [] # os.walk返回一个生成器,每次迭代时返回当前目录路 ...

  3. 使用js开发一个快速打开前端项目的alfred插件

    使用js开发一个快速打开前端项目的插件 目录 前言 使用的技术栈 步骤 问题发现 待优化 前言 一直以来开发都是先打开vscode,然后选择项目,在项目多的情况下会觉得挺繁琐:如果同时打开了许多vsc ...

  4. java实现 微信公众号推送消息 ,cv 就可运行!!!

    一,注册公众号 1,官网地址:申请测试公众号 地址: 微信公众平台 (qq.com) 文档地址:微信开放文档 (qq.com) 2,注册后可以查看自己的appId 和 appsecret 3,创建模板 ...

  5. Vue2系列(lqz)——slot插槽 (内容分发)、2 transition过渡、3 生命周期、4 swiper学习、5 自定义组件的封装、6 自定义指令、7 过滤器

    文章目录 1 slot插槽 (内容分发) 1.1 基本使用 1.2 插槽应用场景1 1.3 插槽应用场景2 1.4 具名插槽 2 transition过渡 3 生命周期 4 swiper学习 5 自定 ...

  6. 服务链路追踪 —— SpringCloud Sleuth

    Sleuth 简介 随着业务的发展,系统规模变得越来越大,微服务拆分越来越细,各微服务间的调用关系也越来越复杂.客户端请求在后端系统中会经过多个不同的微服务调用来协同产生最后的请求结果,几平每一个请求 ...

  7. [ABC202E] Count Descendants 题解

    Count Descendants 题目大意 给定一颗以 \(1\) 为根的树,多次询问求某点的子树中深度为给定值的点的个数. 思路分析 对于每个深度开一个 vector,从大到小存下这个深度的所有点 ...

  8. 通过Lambda函数的方式获取属性名称

    前言: 最近在使用mybatis-plus框架, 常常会使用lambda的方法引用获取实体属性, 避免出现大量的魔法值. public List<User> listBySex() { L ...

  9. P4156 [WC2016]论战捆竹竿 题解

    题目链接 题意描述 给定一个字符串 \(s\),你初始拥有一个空串 \(t\),每次可以选择这个字符串的一个 Border,去掉它后接在 \(t\) 的后面,操作后 \(s\) 不变,给出一个上限 \ ...

  10. JS深入之内存详解,数据结构,存储方式

    理解了本文,就知道深拷贝和浅拷贝的底层,了解赋值的底层原理. 可以结合另一篇文章一起食用:深拷贝与浅拷贝的区别,实现深拷贝的方法介绍. 以下是正文: 栈数据结构 栈的结构就是后进先出(LIFO),如果 ...