当前位置:网站首页>Atcoder beginer contest 261e / / bitwise thinking + DP
Atcoder beginer contest 261e / / bitwise thinking + DP
2022-07-25 12:56:00 【Jakon_】
Topic link :E - Many Operations (atcoder.jp)
The question :
Give a number x, as well as n Operations (ti,ai):
When t = 1 when , take x & a
When t = 2 when , take x | a
When t = 3 when , take x ^ a
And print them separately n Number :x Before proceeding 1 Print after operation , Go further before 2 Print after operation ,... , Go further before n Print after operation .
Ideas :
because x、ai All less than
, Every operation is a bit operation , Then think according to each binary , At most 30 bits , The initial value of each can only be 0、1, Just preprocess it first , Each is initially 0、1 when , Before proceeding i Time (1~n) The value after operation , You can quickly find any number for front i The value after the first operation .
Code :
//dp
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, x, t[N], a[N];
bool f[N][30][2]; //fi,j,k: For the second j position , For the initial k Under the circumstances , Before proceeding i The value after the first operation
int main()
{
cin >> n >> x;
for(int i = 1; i <= n; i++) scanf("%d%d", &t[i], &a[i]);
for(int i = 0; i < 30; i++) f[0][i][0] = 0, f[0][i][1] = 1;
for(int i = 1; i <= n; i++)
for(int j = 0; j < 30; j++)
for(int k = 0; k < 2; k++)
if(t[i] == 1) f[i][j][k] = f[i - 1][j][k] & (a[i] >> j & 1);
else if(t[i] == 2) f[i][j][k] = f[i - 1][j][k] | (a[i] >> j & 1);
else if(t[i] == 3) f[i][j][k] = f[i - 1][j][k] ^ (a[i] >> j & 1);
for(int i = 1; i <= n; i++)
{
int res = 0;
for(int j = 0; j < 30; j++) res += f[i][j][x >> j & 1] << j;
printf("%d\n", x = res);
}
return 0;
}边栏推荐
- Business visualization - make your flowchart'run'(3. Branch selection & cross language distributed operation node)
- CONDA common commands: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem
- JS 中根据数组内元素的属性进行排序
- Jenkins configuration pipeline
- Chapter5 : Deep Learning and Computational Chemistry
- [ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro
- Plus SBOM: assembly line BOM pbom
- 零基础学习CANoe Panel(15)—— 文本输出(CAPL Output View )
- [problem solving] ibatis.binding BindingException: Type interface xxDao is not known to the MapperRegistry.
- ECCV 2022 | climb to the top semantickitti! Semantic segmentation of LIDAR point cloud based on two-dimensional prior assistance
猜你喜欢

Seven lines of code made station B crash for three hours, but "a scheming 0"

【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021

Interviewer: "classmate, have you ever done a real landing project?"

Eccv2022 | transclassp class level grab posture migration

A hard journey

【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)

交换机链路聚合详解【华为eNSP】

clickhouse笔记03-- Grafana 接入ClickHouse
![[today in history] July 25: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone](/img/f6/d422367483542a0351923f2df27347.jpg)
[today in history] July 25: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone

Zero basic learning canoe panel (16) -- clock control/panel control/start stop control/tab control
随机推荐
What is ci/cd?
公安部:国际社会普遍认为中国是世界上最安全的国家之一
程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠
Selenium uses -- XPath and analog input and analog click collaboration
Use of Spirng @conditional conditional conditional annotation
Detailed explanation of switch link aggregation [Huawei ENSP]
如何用因果推断和实验驱动用户增长? | 7月28日TF67
我想问DMS有没有定时备份某一个数据库的功能?
485 communication (detailed explanation)
Keeping MySQL highly available
Perf performance debugging
业务可视化-让你的流程图'Run'起来(3.分支选择&跨语言分布式运行节点)
The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
R language uses wilcox The test function performs Wilcox signed rank test to obtain the confidence interval of the population median (the default output result includes the confidence interval of 95%
Alibaba cloud technology expert Qin long: reliability assurance is a must - how to carry out chaos engineering on the cloud?
A hard journey
启牛开的证券账户安全吗?是怎么开账户的
使用vsftpd服务传输文件(匿名用户认证、本地用户认证、虚拟用户认证)
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary problem solution (g, J, K, l)
conda常用命令:安装,更新,创建,激活,关闭,查看,卸载,删除,清理,重命名,换源,问题