CF878D D. Magic Breeding bitset
4 seconds
1024 megabytes
standard input
standard output
Nikita and Sasha play a computer game where you have to breed some magical creatures. Initially, they have kcreatures numbered from 1 to k. Creatures have n different characteristics.
Sasha has a spell that allows to create a new creature from two given creatures. Each of its characteristics will be equal to the maximum of the corresponding characteristics of used creatures. Nikita has a similar spell, but in his spell, each characteristic of the new creature is equal to the minimum of the corresponding characteristics of used creatures. A new creature gets the smallest unused number.
They use their spells and are interested in some characteristics of their new creatures. Help them find out these characteristics.
The first line contains integers n, k and q (1 ≤ n ≤ 105, 1 ≤ k ≤ 12, 1 ≤ q ≤ 105) — number of characteristics, creatures and queries.
Next k lines describe original creatures. The line i contains n numbers ai1, ai2, ..., ain (1 ≤ aij ≤ 109) — characteristics of the i-th creature.
Each of the next q lines contains a query. The i-th of these lines contains numbers ti, xi and yi (1 ≤ ti ≤ 3). They denote a query:
- ti = 1 means that Sasha used his spell to the creatures xi and yi.
- ti = 2 means that Nikita used his spell to the creatures xi and yi.
- ti = 3 means that they want to know the yi-th characteristic of the xi-th creature. In this case 1 ≤ yi ≤ n.
It's guaranteed that all creatures' numbers are valid, that means that they are created before any of the queries involving them.
For each query with ti = 3 output the corresponding characteristic.
2 2 4
1 2
2 1
1 1 2
2 1 2
3 3 1
3 4 2
2
1
5 3 8
1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
1 1 2
1 2 3
2 4 5
3 6 1
3 6 2
3 6 3
3 6 4
3 6 5
5
2
2
3
4
In the first sample, Sasha makes a creature with number 3 and characteristics (2, 2). Nikita makes a creature with number 4 and characteristics (1, 1). After that they find out the first characteristic for the creature 3 and the second characteristic for the creature 4.
题目还是很好懂的吧
一开始的时候,给你k个怪兽,每个怪兽有n个属性。
然后现在你有三个操作:
第一个操作是用x和y怪物生成一个新的怪物,这个怪物的属性是x和y的最大值
第二个操作是用x和y怪物生成一个新的怪物,这个怪物的属性是x和y的最小值
第三个操作是询问第x个怪物的第y个属性是多少。
用并查集维护?不太行啊,这么多操作呢,根本无法模拟
这个bitset很有灵性
&用来取大,|用来取小
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+;
bitset<>S[N];
int a[][N];
int n,k,q;
int main()
{
scanf("%d%d%d",&n,&k,&q);
for(int i=; i<k; i++)
{
for(int j=; j<; j++)
if(j&(<<i))S[i].set(j);
for(int j=; j<n; j++)scanf("%d",&a[i][j]);
}
int tot=k;
while(q--)
{
int op,x,y;
scanf("%d%d%d",&op,&x,&y),x--,y--;
if(op==)S[tot++]=S[x]&S[y];
else if(op==)S[tot++]=S[x]|S[y];
else
{
vector<pair<int,int> >Q;
for(int i=; i<k; i++)Q.push_back({a[i][y],i});
sort(Q.begin(),Q.end());
int b = ;
for(int i=; i<k; i++)
{
b|=<<Q[i].second;
if(S[x][b])
{
cout<<Q[i].first<<endl;
break;
}
}
}
}
}
CF878D D. Magic Breeding bitset的更多相关文章
- 【CF878D】Magic Breeding bitset
[CF878D]Magic Breeding 题意:有k个物品,每个物品有n项属性值,第i个人的第j个属性值为aij,有q个操作: 1 x y 用x和y合成一个新的物品,新物品的编号是++k,新物品的 ...
- Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...
- [cf878D]Magic Breeding
对于每一行,用一个2^12个01来表示,其中这一行就是其中所有为1的点所代表的行(i二进制中包含的行)的max的min,然后就可以支持取max和min了,查询只需要枚举答案即可 1 #include& ...
- Codeforces 878D - Magic Breeding(bitset,思维题)
题面传送门 很容易发现一件事情,那就是数组的每一位都是独立的,但由于这题数组长度 \(n\) 很大,我们不能每次修改都枚举每一位更新其对答案的贡献,这样复杂度必炸无疑.但是这题有个显然的突破口,那就是 ...
- Codeforces 632F Magic Matrix(bitset)
题目链接 Magic Matrix 考虑第三个条件,如果不符合的话说明$a[i][k] < a[i][j]$ 或 $a[j][k] < a[i][j]$ 于是我们把所有的$(a[i][j ...
- Codeforces 632F - Magic Matrix(暴力 bitset or Prim 求最小生成树+最小瓶颈路)
题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将 ...
- hdu 4605 Magic Ball Game
http://acm.hdu.edu.cn/showproblem.php?pid=4605 可以离线求解 把所以可能出现的 magic ball 放在一个数组里(去重),从小到大排列 先不考虑特殊 ...
- codeforces 632F. Magic Matrix
题目链接 给一个n*n的矩阵, 问是否对角线上的元素全都为0, a[i][j]是否等于a[j][i], a[i][j]是否小于等于max(a[i][k], a[j][k]), k为任意值. 前两个都好 ...
- [搜索] hdu 4016 Magic Bitwise And Operation
主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=4016 Magic Bitwise And Operation Time Limit: 6000/30 ...
随机推荐
- POJ 3017 Cut the Sequence (单调队列优化DP)
题意: 给定含有n个元素的数列a,要求将其划分为若干个连续子序列,使得每个序列的元素之和小于等于m,问最小化所有序列中的最大元素之和为多少?(n<=105.例:n=8, m=17,8个数分别为2 ...
- MovieReview—Kingsman THE SECRET SERVICE(王牌特工之特工学院)
Brain Storming Mr. Valentine's Day see excess human beings as the Earth's virus and try to e ...
- 激光推送报错:APNs is not available,please check your provisioning profile and certification 和 设置别名问题 app not registed, give up set tag:
前几天,项目中用到了推送功能,就集成了激光,遇到了2个问题,就给大家分享一下, 第一个问题: 在集成的过程是按照激光的文档做的,但是最后配置完了,一运行,就打印出这么一句话, APNs is not ...
- AMD、CMD规范
本文原链接:https://cloud.tencent.com/developer/article/1177217 AMD && CMD 前言 一.模块 二.CommonJS 三.AM ...
- Maven settings.xml配置详解
首先:Maven中央仓库的搜索全部公共jar包的地址是,http://search.maven.org/ ===Maven基础-默认中央仓库============================== ...
- CMDB 数据加密 最终整合API验证+AES数据加密
当CMDB运行在内网的时候,经过API验证的三关是没有问题的,但是如果运行在外网,有一个问题是,黑客截取后的访问速度比客户端快的时候还会造成数据泄露.为了解决这个问题,就要对数据进行加密 RSA加密 ...
- linux - mysql 安装教程
环境介绍>>>>>>>>>>>>>>>>>> 操作系统:Centos 7 mysql数据库版 ...
- SpringBoot(一)_Eclipse的安装和使用
1.Eclipse中安装STS插件: Help -> Eclipse Marketplace… Search或选择“Popular”标签,选择Spring Tool Suite (STS) fo ...
- mysql crash cource 书中实例
样例表 CREATE TABLE customers( cust_id int NOT NULL AUTO_INCREMENT, cust_name char(50) ...
- Java面向对象基础 ——面试题
1面向对象基础 JAVA基础语法自行掌握. 三大特性: 一 封装:★★★★★ 概念:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 好处:将变化隔离:便于使用:提高重用性:安全性. 封装原则: ...