当前位置:网站首页>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;
}
边栏推荐
- 关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
- could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
- 【Unity编译器扩展之进度条】
- Will domestic websites use Hong Kong servers be blocked?
- oracle创建用户
- The master teaches you the 3D real-time character production process, the game modeling process sharing
- tiup telemetry
- 数据类型-整型(C语言)
- 软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
- 机器学习(公式推导与代码实现)--sklearn机器学习库
猜你喜欢

Mysql_14 存储引擎

Senior game modelers tell newbies, what are the necessary software for game scene modelers?
Handwritten Distributed Configuration Center (1)

Modelers experience sharing: model study method

SV 类的虚方法 多态

2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)

oracle创建用户

could not build server_names_hash, you should increase server_names_hash_bucket_size: 32

【云原生--Kubernetes】调度约束

TinyMCE禁用转义
随机推荐
怎样进行在不改变主线程执行的时候,进行日志的记录
仿网易云音乐小程序-uniapp
Some thoughts on writing
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
软件测试面试题:手工测试与自动测试有哪些区别?
KT148A voice chip ic working principle and internal architecture description of the chip
Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
【LeetCode】滑动窗口题解汇总
TinyMCE disable escape
软件开发工具的技术要素
SV 类的虚方法 多态
matlab中rcosdesign函数升余弦滚降成型滤波器
【云原生--Kubernetes】Pod控制器
工业物联网 —— 新型数据库的召唤
E - Many Operations (按位考虑 + dp思想记录操作后的结果
ARC129E Yet Another Minimization 题解 【网络流笔记】
情侣牵手[贪心 & 抽象]
2022杭电多校 第三场 B题 Boss Rush
tiup telemetry