D. Magic Breeding

link

http://codeforces.com/contest/878/problem/D

description

Nikita and Sasha play a computer game where you have to breed some magical creatures. Initially, they have k creatures 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 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.

Output

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

Examples

input

2 2 4

1 2

2 1

1 1 2

2 1 2

3 3 1

3 4 2

output

2

1

input

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

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个属性是多少。

题解

对于每个属性而言,就k种情况。

考虑最简单的情况,属性只有0和1。那么我们暴力可以用一个数字来表示怪兽的每个属性的取值。

取最大就是取|,最小就是取&,然后最后看是0是1即可。

但是现在属性是1e9范围的,我们也可以这样做,我们用1表示这个位置的属性至少为这么大。

然后和之前一样做,最后输出最大的合法属性即可。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
bitset<4096>S[maxn];
int a[12][maxn];
int n,k,q,tot;
int main(){
scanf("%d%d%d",&n,&k,&q);
tot=k;
for(int i=0;i<k;i++){
for(int j=0;j<4096;j++){
if(j&(1<<i))S[i].set(j);
}
for(int j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}
for(int qq=0;qq<q;qq++){
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
x--,y--;
if(op==1)S[tot++]=S[x]&S[y];
if(op==2)S[tot++]=S[x]|S[y];
if(op==3){
vector<pair<int,int> >Q;
for(int i=0;i<k;i++){
Q.push_back(make_pair(a[i][y],i));
}
sort(Q.begin(),Q.end());
int b = 0;
for(int i=0;i<k;i++){
b|=(1<<Q[i].second);
if(S[x][b]){
cout<<Q[i].first<<endl;
break;
}
}
}
}
}

Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算的更多相关文章

  1. Codeforces Round #443 (Div. 2) C: Short Program - 位运算

    传送门 题目大意: 输入给出一串位运算,输出一个步数小于等于5的方案,正确即可,不唯一. 题目分析: 英文题的理解真的是各种误差,从头到尾都以为解是唯一的. 根据位运算的性质可以知道: 一连串的位运算 ...

  2. Codeforces Round #499 (Div. 2) F. Mars rover_dfs_位运算

    题解: 首先,我们可以用 dfsdfsdfs 在 O(n)O(n)O(n) 的时间复杂度求出初始状态每个点的权值. 不难发现,一个叶子节点权值的取反会导致根节点的权值取反当且仅当从该叶子节点到根节点这 ...

  3. Codeforces Round #626 (Div. 2) D. Present(位运算)

    题意: 求n个数中两两和的异或. 思路: 逐位考虑,第k位只需考虑0~k-1位,可通过&(2k+1-1)得到一组新数. 将新数排序,当两数和在[2k,2k+1)和[2k+1+2k,2k+2)之 ...

  4. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  5. Codeforces Round #443 (Div. 1) A. Short Program

    A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...

  6. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  7. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  8. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  9. Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟

    A. Magic Spheres   Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. ...

随机推荐

  1. C# 属性(Property)和字段(Field)的区别

    导读: 近期学习过程中发现了一些问题,我的学习只是学习,敲代码就是敲代码,没有加入思考,也不问为什么就直接去敲人家写好的例子去敲,把知识都学死了,逐渐散失了思考能力,所以学习的兴趣大打折扣,正如那句话 ...

  2. 实战--Keepalived和LVS实现负载高可用

    显然,只有上一篇的操作,在WEB运维技术中,只能承担一半的角色. 想像一下,如何LVS本身倒了,肿么办?后端的NGINX再多,也只能是干着急,请求过来不呀! 所以,在本篇时,我们来实现LVS永不倒, ...

  3. EF批量插入数据(Z.EntityFramework.Extensions)

    EF用原生的插入数据方法DbSet.ADD()和 DbSet.AddRange()都很慢.所以要做大型的批量插入只能另选它法. 1.Nugget 2.代码 using EF6._0Test.EF; u ...

  4. 使用Eclipse绑定Tomcat并发布应用

    l 步骤1:获得服务器运行环境配置,Window/Preferences/Server/Runtime Environmen l步骤2:添加服务器 l步骤3:选择服务器在硬盘的地址,然后所有的都是确定 ...

  5. PHP查询数据库较慢,nginx 超时 返回 504:Sorry, the page you are looking for is currently unavailable.

    现象: PHP查询数据库较慢,大约 60s 后 nginx 返回 504:Sorry, the page you are looking for is currently unavailable. 检 ...

  6. 【Android】Android 代码判断是否获取ROOT权限(二)

    [Android]Android 代码判断是否获取ROOT权限 方法比较简单,直接粘贴代码 /** * 判断当前手机是否有ROOT权限 * @return */ public boolean isRo ...

  7. net core体系-web应用程序-4net core2.0大白话带你入门-4asp.net core配置项目访问地址

    asp.net core配置访问地址  .net core web程序,默认使用kestrel作为web服务器. 配置Kestrel Urls有四种方式,我这里只介绍一种.其它方式可自行百度. 在Pr ...

  8. Codeforces 666E E - Forensic Examination SA + 莫队 + 线段树

    E - Forensic Examination 我也不知道为什么这个复杂度能过, 而且跑得还挺快, 数据比较水? 在sa上二分出上下界, 然后莫队 + 线段树维护区间众数. #include< ...

  9. {}动态规划}记忆化dp

    先搞个模板 #include<stdio.h> #include<string.h> using namespace std; typedef long long ll; ]; ...

  10. F. Shovels Shop 背包DP

    题意: 商店里有n把铲子 每个铲子有其标价 一个人要买k吧 有m个优惠政策 每个优惠政策有两个元素x,y 表示   正好买x个铲子的时候  这x个铲子中最便宜的y个铲子免单 求用最少的前买到k个铲子 ...