D. Magic Breeding
time limit per test

4 seconds

memory limit per test

1024 megabytes

input

standard input

output

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.

Input

The first line contains integers nk 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 tixi 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.

Output

For each query with ti = 3 output the corresponding characteristic.

Examples
input

Copy
2 2 4
1 2
2 1
1 1 2
2 1 2
3 3 1
3 4 2
output

Copy
2
1
input

Copy
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
output

Copy
5
2
2
3
4
Note

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的更多相关文章

  1. 【CF878D】Magic Breeding bitset

    [CF878D]Magic Breeding 题意:有k个物品,每个物品有n项属性值,第i个人的第j个属性值为aij,有q个操作: 1 x y 用x和y合成一个新的物品,新物品的编号是++k,新物品的 ...

  2. Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算

    D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...

  3. [cf878D]Magic Breeding

    对于每一行,用一个2^12个01来表示,其中这一行就是其中所有为1的点所代表的行(i二进制中包含的行)的max的min,然后就可以支持取max和min了,查询只需要枚举答案即可 1 #include& ...

  4. Codeforces 878D - Magic Breeding(bitset,思维题)

    题面传送门 很容易发现一件事情,那就是数组的每一位都是独立的,但由于这题数组长度 \(n\) 很大,我们不能每次修改都枚举每一位更新其对答案的贡献,这样复杂度必炸无疑.但是这题有个显然的突破口,那就是 ...

  5. Codeforces 632F Magic Matrix(bitset)

    题目链接  Magic Matrix 考虑第三个条件,如果不符合的话说明$a[i][k] < a[i][j]$ 或 $a[j][k] < a[i][j]$ 于是我们把所有的$(a[i][j ...

  6. Codeforces 632F - Magic Matrix(暴力 bitset or Prim 求最小生成树+最小瓶颈路)

    题面传送门 开始挖老祖宗(ycx)留下来的东西.jpg 本来想水一道紫题作为 AC 的第 500 道紫题的,结果发现点开了道神题. 首先先讲一个我想出来的暴力做法.条件一和条件二直接扫一遍判断掉.先将 ...

  7. hdu 4605 Magic Ball Game

    http://acm.hdu.edu.cn/showproblem.php?pid=4605 可以离线求解 把所以可能出现的 magic ball  放在一个数组里(去重),从小到大排列 先不考虑特殊 ...

  8. codeforces 632F. Magic Matrix

    题目链接 给一个n*n的矩阵, 问是否对角线上的元素全都为0, a[i][j]是否等于a[j][i], a[i][j]是否小于等于max(a[i][k], a[j][k]), k为任意值. 前两个都好 ...

  9. [搜索] hdu 4016 Magic Bitwise And Operation

    主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=4016 Magic Bitwise And Operation Time Limit: 6000/30 ...

随机推荐

  1. malloc/free函数

    一.malloc 函数原型:void *malloc(unsigned int size); 功       能:在内存的动态存储区中分配一个长度为size的连续空间. 返  回 值:指向所分配的连续 ...

  2. node 把base数据合成图片

    var cr = new Buffer(img_Datas, 'base64'); var img = params.img_path + '/' + picDevNo + '_' + params. ...

  3. UVA208 Firetruck 消防车(并查集,dfs)

    要输出所有路径,又要字典序,dfs最适合了,用并查集判断1和目的地是否连通即可 #include<bits/stdc++.h> using namespace std; ; int p[m ...

  4. javaweb基础(10)_HttpServletRequest原理介绍

    一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...

  5. JSON.stringify(value[, replacer[, space]])

    1. JSON.stringify(value[, replacer[, space]]);value 必需 对象或数组,需要转换成json字符串的数据replacer 可选 函数或数组space 可 ...

  6. Java语言中的异常处理

    Java语言中的异常处理包括声明异常.抛出异常.捕获异常和处理异常四个环节.   throw用于抛出异常.   throws关键字可以在方法上声明该方法要抛出的异常,然后在方法内部通过throw抛出异 ...

  7. hash 哈希查找复杂度为什么这么低?

    hash 哈希查找复杂度为什么这么低? (2017-06-23 21:20:36) 转载▼   分类: c from: 作者:jillzhang 出处:http://jillzhang.cnblogs ...

  8. json转换为字典

    str---dict ata_dict=json.loads(data)

  9. 【jenkins】jenkins执行nohup java报错

    nohup:failed to run command 'java':No such file or directory 这是因为jenkins只认绝对路径.在shell里面有涉及到文件的都应该写成绝 ...

  10. 01 Django基础知识

    相关概念 软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模块都有特定的功能 ...