当前位置:网站首页>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;
}边栏推荐
- 微软提出CodeT:代码生成新SOTA,20个点的性能提升
- 手写一个博客平台~第一天
- JS sorts according to the attributes of the elements in the array
- Zero basic learning canoe panel (13) -- trackbar
- 力扣 83双周赛T4 6131.不可能得到的最短骰子序列、303 周赛T4 6127.优质数对的数目
- 零基础学习CANoe Panel(14)——二极管( LED Control )和液晶屏(LCD Control)
- 2022.07.24(LC_6126_设计食物评分系统)
- 【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12
- MySQL implements inserting data from one table into another table
- AtCoder Beginner Contest 261E // 按位思考 + dp
猜你喜欢

web安全入门-UDP测试与防御

Jenkins configuration pipeline

零基础学习CANoe Panel(16)—— Clock Control/Panel Control/Start Stop Control/Tab Control

【OpenCV 例程 300篇】239. Harris 角点检测之精确定位(cornerSubPix)

2022.07.24(LC_6125_相等行列对)

EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心
软件测试流程包括哪些内容?测试方法有哪些?

Microsoft proposed CodeT: a new SOTA for code generation, with 20 points of performance improvement

Clickhouse notes 03-- grafana accesses Clickhouse

【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12
随机推荐
[advanced C language] dynamic memory management
《富兰克林自传》修身
Azure Devops (XIV) use azure's private nuget warehouse
Word style and multi-level list setting skills (II)
MySQL remote connection permission error 1045 problem
What is ci/cd?
Create directories and subdirectories circularly
Monit installation and use
Lu MENGZHENG's "Fu of broken kiln"
弹性盒子(Flex Box)详解
Perf performance debugging
Selenium use -- installation and testing
The programmer's father made his own AI breast feeding detector to predict that the baby is hungry and not let the crying affect his wife's sleep
阿里云技术专家秦隆:可靠性保障必备——云上如何进行混沌工程?
【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone
我在源头SQLServer里面登记绝对删除的数据,传到MaxComputer,在数据清洗的时候写绝对
go : gin 自定义日志输出格式
[problem solving] ibatis.binding BindingException: Type interface xxDao is not known to the MapperRegistry.
2022.07.24 (lc_6124_the first letter that appears twice)
shell基础知识(退出控制、输入输出等)