当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps
刘润直播预告 | 顶级高手,如何创造财富
Will domestic websites use Hong Kong servers be blocked?
《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
电赛必备技能___定时ADC+DMA+串口通信
元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
数据类型-整型(C语言)
标识符、关键字、常量 和变量(C语言)
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
随机推荐
2022多校第二场 K题 Link with Bracket Sequence I
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
Chinese and Japanese color style
测试经理要不要做测试执行?
Privacy Computing Overview
【LeetCode】双指针题解汇总
tiup update
图解 Canvas 入门
How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer
ansible学习笔记分享-含剧本示例
.net(C#)获取两个日期间隔的年月日
情侣牵手[贪心 & 抽象]
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
找不到DiscoveryClient类型的Bean
E - Distance Sequence (前缀和优化dp
阅读笔记:如何理解DevOps?
刘润直播预告 | 顶级高手,如何创造财富
统计单词(DAY 101)华中科技大学考研机试题
2022牛客多校第三场 A Ancestor
Senior game modelers tell newbies, what are the necessary software for game scene modelers?