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. 文心一言 VS 讯飞星火 VS chatgpt (79)-- 算法导论7.4 4题

    四.请用go语言,证明:RANDOMIZED-QUICKSORT 期望运行时间是 Ω(nlgn). 文心一言: 首先,为了证明RANDOMIZED-QUICKSORT的期望运行时间是Ω(nlg n), ...

  2. iOS视图控件的内容显示和离屏渲染流程

    iOS中UI控件内容显示流程 UIKit界面组成 iOS中组成页面的各个元素基本来自UIKit,我们可以修改布局或自定义绘制来修改UIKit元素的默认展示. UIView的页面显示内容有CALayer ...

  3. vue3+ts Axios封装—重复请求拦截

    创建好vue3项目 1.安装Axios与Element Plus Axios安装 npm install axios Element Plus 安装 官网入口:https://element-plus ...

  4. vsftp简单配置

    添加用户 vi /etc/pam.d/vsftdp 注释掉 auth required pam_shells.so

  5. 【目标检测】RCNN算法实现

    一.前言 RCNN(Regions with CNN features)算法由Ross Girshick在2014年的论文"Rich feature hierarchies for accu ...

  6. 【SpringBoot实战】开发入门--快速创建springboot程序

    前言 本片博客记录快速创建springboot工程的使用spring initializr创建.开发环境JDK1.8.IDEA.maven. SpringBoot 优点 可快速构建spring应用 直 ...

  7. [SDR] SDR 教程实战 —— 利用 GNU Radio + HackRF 手把手深入了解蓝牙协议栈(从电磁波 -> 01数据流 -> 蓝牙数据包)

    目录 0.前言 1.体验 2.代码解析 2.1 目录结构 2.2 main.py 2.3 grc gnu radio 流程图 2.4 如何从 01 数据流中解析出 BLE 广播包 2.4.1 物理层 ...

  8. 万字长文教你实现华为云IoT+OpenHarmony智能家居开发

    本文分享自华为云社区<华为云IoT+OpenHarmony的智能家居开发>,作者:袁睿. 一.选题说明 1. 选题为基于OpenHarmony的智能家居,应用场景为户用,受益人群为住户. ...

  9. tarjan强连通分量

    int scc[N],sc;//结点i所在scc的编号 int sz[N]; //强连通i的大小 //dfn(u)为搜到结点u时的次序编号 //low(u)为u或u的子树能够追溯到的最早的栈中节点的次 ...

  10. 【遥遥领先】Eolink IDEA 插件:零代码入侵,自动生成接口

    省流版: Eolink 有 IDEA 插件吗? 有,而且遥遥领先!我们在一年半之前就发布了,而且功能更丰富! IDEA 插件市场搜索"Eolink Apikit"即可安装使用. 使 ...