当前位置:网站首页>E - Many Operations (按位考虑 + dp思想记录操作后的结果
E - Many Operations (按位考虑 + dp思想记录操作后的结果
2022-08-05 00:08:00 【__Rain】
E - Many Operations
思路:
虽然第 i i i 次操作的初始值是第 i − 1 i-1 i−1 次操作后的结果,但是按位考虑,开始操作时每一位只能是 0 0 0 或者 1 1 1,并且每次操作顺序每次都是一样的
可以想到用 d p dp dp 思想记录下来每一位按顺序操作后的结果
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;
}
边栏推荐
猜你喜欢
导入JankStats检测卡帧库遇到问题记录
How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer
Getting started with 3D modeling for games, what modeling software can I choose?
性能测试如何准备测试数据
Security software Avast and Symantec NortonLifeLock merge with UK approval, market value soars 43%
Handwritten Distributed Configuration Center (1)
没有这些「伪需求」,产品经理的 KPI 怎么完成?
The master teaches you the 3D real-time character production process, the game modeling process sharing
安全软件 Avast 与赛门铁克诺顿 NortonLifeLock 合并案获英国批准,市值暴涨 43%
jenkins发送邮件系统配置
随机推荐
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
MAUI Blazor 权限经验分享 (定位,使用相机)
【数据挖掘概论】数据挖掘的简单描述
~ hand AHB - APB Bridge 】 【 AMBA AHB bus
Ab3d.PowerToys and Ab3d.DXEngine Crack
Implementation principle of golang coroutine
Detailed explanation of common DNS resource record types
#yyds dry goods inventory #Switching equipment serious packet loss troubleshooting
怎么将自己新文章自动推送给自己的粉丝(巨简单,学不会来打我)
KT148A电子语音芯片ic方案适用的场景以及常见产品类型
关于使用read table 语句
.net (C#) get year month day between two dates
uinty lua 关于异步函数的终极思想
SQL关联表更新
Xiaohei leetcode surfing: 94. Inorder traversal of binary tree
Nuclei(二)进阶——深入理解workflows、Matchers和Extractors
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
小黑leetcode冲浪:94. 二叉树的中序遍历
对写作的一些感悟
2022年华数杯数学建模