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 ...
随机推荐
- iOS Programming Autorotation, Popover Controllers, and Modal View Controllers
iOS Programming Autorotation, Popover Controllers, and Modal View Controllers 自动旋转,Popover 控制器,Moda ...
- Windows UEFI 安装策略的一个细节
在计算机已连接任何带Windows Boot Manager的硬盘的时候,系统自己不会创建EFI分区,而是用之前的
- 2017年团体程序设计天梯赛 - 大区赛 L3-3
题意:有向图找哈密顿回路 比赛的时候剪枝只剪了vis 状压没剪对 反而只拿17分... 比赛结束后还去看了一发这个NP问题的QB(快速回溯法...但是对于本题好像大材小用...) 上网看了一个神犇的写 ...
- caffe parse_log.sh
画loss曲线需要用到此shell脚本 #!/bin/bash # Usage parse_log.sh caffe.log # It creates the following two text f ...
- HTML 标签(一)
HTML HTML:超文本编辑语言(标签语言) 浏览器顺序渲染,从上到下,从左到右 是树型的 html格式 标签的属性是关键 meta标签 可提供有关页面的元信息 <meta charset=& ...
- MySql下最好用的数据库管理工具是哪个
MySql下最好用的数据库管理工具是哪个? 维基上有个很全的列表: https://en.wikipedia.org/wiki/Comparison_of_database_tools 1. ph ...
- iOS 打印系统字体
NSArray * array = [UIFont familyNames]; for( NSString *familyName in array ){ printf( "Family: ...
- iOS 资源大全整理
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...
- c++ 指针数组,输入4个季度的花费,计算出总花费
#include <iostream> #include <array> #include <string> const int Seasons = 4; cons ...
- chrome浏览器跳过(忽略)所有的js断点
在调试程序时我们经常通过打断点的方式来跟踪代码的执行流程,所以可能会在很多时候打很多断点,当我们知道了程序大概的执行流程之后,这时候断点就不太需要了.但是我们又不想马上把所有的断点清除掉,因为我们打的 ...