当前位置:网站首页>E - Many Operations (bitwise consideration + dp thought to record the result after the operation
E - Many Operations (bitwise consideration + dp thought to record the result after the operation
2022-08-05 00:21:00 【__Rain】
E - Many Operations
思路:
虽然第 i i i The initial value of the operation is th i − 1 i-1 i−1 the result after the operation,But consider bitwise,Each bit can only be at the beginning of the operation 0 0 0 或者 1 1 1,And the sequence of operations is the same every time
可以想到用 d p dp dp The idea is to record the result of each bit in sequence
f [ i ] [ j ] [ k ] f[i][j][k] f[i][j][k] 表示第 j j j 位初始值为 k k k ,进行 i i i 次操作后的值
code:
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define mem(x, d) memset(x, d, sizeof(x))
#define eps 1e-6
using namespace std;
const int maxn = 2e5 + 9;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll n, m;
bool f[maxn][30][2];
// f[i][j][k] 表示第j位初始值为k,进行 i 次操作后的值
void work()
{
cin >> n >> m;
vector <int>t(n + 1), a(n + 1);
for(int i = 1; i <= n; ++i){
cin >> 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){
int x = (a[i] >> j & 1);
for(int k = 0; k < 2; ++k){
if(t[i] == 1){
f[i][j][k] = f[i-1][j][k] & x;
}
else if(t[i] == 2){
f[i][j][k] = f[i-1][j][k] | x;
}
else {
f[i][j][k] = f[i-1][j][k] ^ x;
}
}
}
}
for(int i = 1; i <= n; ++i){
int ans = 0;
for(int j = 0; j < 30; ++j){
int k = (m >> j & 1);
if(f[i][j][k]) ans += 1 << j;
}
cout << ans << endl;
m = ans;
}
}
int main()
{
ios::sync_with_stdio(0);
// int TT;cin>>TT;while(TT--)
work();
return 0;
}
边栏推荐
猜你喜欢

【LeetCode】滑动窗口题解汇总
![[Cloud Native--Kubernetes] Pod Controller](/img/e1/1a8cc82223f9a9be79ebbf1211e9a4.png)
[Cloud Native--Kubernetes] Pod Controller

【LeetCode】双指针题解汇总

Will domestic websites use Hong Kong servers be blocked?

Essential knowledge for entry-level 3D game modelers

【Valentine's Day special effects】--Canvas realizes full screen love

Getting started with 3D modeling for games, what modeling software can I choose?

could not build server_names_hash, you should increase server_names_hash_bucket_size: 32

TinyMCE disable escape

数据类型-整型(C语言)
随机推荐
看图识字,DELL SC4020 / SCv2000 控制器更换过程
统计单词(DAY 101)华中科技大学考研机试题
Cloud native - Kubernetes 】 【 scheduling constraints
【unity编译器扩展之模型动画拷贝】
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
数据类型-整型(C语言)
Some thoughts on writing
简单的顺序结构程序(C语言)
uinty lua 关于异步函数的终极思想
"No title"
LeetCode Hot 100
标识符、关键字、常量 和变量(C语言)
软件测试面试题:网络七层协仪具体?
Huggingface入门篇 II (QA)
软件开发工具的技术要素
leetcode经典例题——单词拆分
测试经理要不要做测试执行?
tiup update
MVCC是什么
2022牛客多校第三场 A Ancestor