当前位置:网站首页>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;
}
边栏推荐
- 【七夕情人节特效】-- canvas实现满屏爱心
- [Cloud Native--Kubernetes] Pod Controller
- 统计单词(DAY 101)华中科技大学考研机试题
- Privacy Computing Overview
- 找不到DiscoveryClient类型的Bean
- NebulaGraph v3.2.0 Release Note,对查询最短路径的性能等多处优化
- [LeetCode] Summary of Matrix Simulation Related Topics
- MAUI Blazor 权限经验分享 (定位,使用相机)
- NebulaGraph v3.2.0 Release Note, many optimizations such as the performance of querying the shortest path
- Three tips for you to successfully get started with 3D modeling
猜你喜欢
KT148A语音芯片ic工作原理以及芯片的内部架构描述
uniapp sharing function - share to friends group chat circle of friends effect (sorting)
Basic web in PLSQL
uniapp 分享功能-分享给朋友群聊朋友圈效果(整理)
Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
MAUI Blazor 权限经验分享 (定位,使用相机)
Nuclei (2) Advanced - In-depth understanding of workflows, Matchers and Extractors
统计单词(DAY 101)华中科技大学考研机试题
MongoDB权限验证开启与mongoose数据库配置
【LeetCode】滑动窗口题解汇总
随机推荐
Chinese and Japanese color style
KT148A语音芯片怎么烧录语音进入芯片里面通过串口和电脑端的工具
NebulaGraph v3.2.0 Release Note,对查询最短路径的性能等多处优化
MAUI Blazor 权限经验分享 (定位,使用相机)
.net(C#)获取两个日期间隔的年月日
NebulaGraph v3.2.0 Release Note, many optimizations such as the performance of querying the shortest path
大师教你3D实时角色制作流程,游戏建模流程分享
游戏3D建模入门,有哪些建模软件可以选择?
Develop a SpaceX website based on the Appian low-code platform
一、爬虫基本概念
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
怎样进行在不改变主线程执行的时候,进行日志的记录
#yyds dry goods inventory #Switching equipment serious packet loss troubleshooting
Flask框架 根据源码分析可扩展点
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
子连接中的参数传递
jenkins send mail system configuration
Nuclei(二)进阶——深入理解workflows、Matchers和Extractors