当前位置:网站首页>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;
}
边栏推荐
- 机器学习(公式推导与代码实现)--sklearn机器学习库
- tensor.nozero(), mask, [mask]
- KT6368A Bluetooth certification problem_FCC and BQB_CE_KC certification or other instructions
- 动态上传jar包热部署
- 电子行业MES管理系统的主要功能与用途
- 关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
- 怎样进行在不改变主线程执行的时候,进行日志的记录
- Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
- 10 种常见的BUG分类
- 【无标题】
猜你喜欢
随机推荐
【LeetCode】矩阵模拟相关题目汇总
redis可视化管理软件Redis Desktop Manager2022
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
工业物联网 —— 新型数据库的召唤
IDEA 文件编码修改
Chinese and Japanese color style
E - Distance Sequence (前缀和优化dp
Modelers experience sharing: model study method
标识符、关键字、常量 和变量(C语言)
MongoDB permission verification is turned on and mongoose database configuration
软件测试面试题:网络七层协仪具体?
【Valentine's Day special effects】--Canvas realizes full screen love
Mysql_14 存储引擎
oracle创建表空间
【LeetCode】双指针题解汇总
The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
[LeetCode] Summary of Matrix Simulation Related Topics
LeetCode Hot 100
软件测试面试题:系统测试的策略有?
简单的顺序结构程序(C语言)




![Couple Holding Hands [Greedy & Abstract]](/img/7d/1cafc000dc58f1c5e2e92150be7953.png)




