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. [PCL]对‘pcl::visualization::CloudViewer::CloudViewer(std::string const&)’未定义的引用

    pcl::visualization::CloudViewer viewer("Cloud Viewer"); 这个时候报错. 试了很多方法,有人说,targe t_link 时候 ...

  2. ZOJ 3469 Food Delivery (区间DP,经典)

    题意: 在x轴上有一家外卖餐馆,有n个顾客站在x轴上不同坐标上且叫了外卖,每个人的脾气不同,每1分钟没有收到外卖就会增加Fi点愤怒值,而外卖小哥的车是有速度的v-1/分钟,问怎样的送餐次序会让所有顾客 ...

  3. windows 10 无法使用内置管理员账户打开应用的解决方案

    步骤 运行regedit.msc: 依次找到:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ ...

  4. Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)

    dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点. #include<bits/stdc++.h> using namespace std; ; int ...

  5. Android(java)学习笔记119:BroadcastReceiver之 短信发送的广播接收者

    有时候,我们需要开发出来一个短信监听器,监听用户发送的短信记录,下面就是一个案例,这里同样需要使用广播机制. 下面同样是代码示例,MainActivity.java 和  activity_main. ...

  6. tpcc-mysql的安装和使用

    tpcc-mysql介绍 TPC(Tracsaction Processing Performance Council) 事务处理性能协会是一个评价大型数据库系统软硬件性能的非盈利的组织,TPC-C是 ...

  7. groff - groff 文档排版系统前端

    总览 (SYNOPSIS) groff [ -abehilpstvzCENRSUVXZ ] [ -wname ] [ -Wname ] [ -mname ] [ -Fdir ] [ -Idir ] [ ...

  8. Kafka 完全分布式集群环境搭建

    思路: 先在主机s1上安装配置,然后远程复制到其它两台主机s2.s3上, 并分别修改配置文件server.properties中的broker.id属性. 1. 搭建前准备 示例共三台主机,主机IP映 ...

  9. OpenCascade:Topo类型转换

    OpenCascade:Topo类型转换 TopoDS_Edge newEdge; if (oldShape.ShapeType()==TopAbs_EDGE) newEdge=TopoDS::Edg ...

  10. Twisted 综述

    Twisted 框架概况 Twisted 是一个有着10多年历史的开源事件驱动框架.Twisted 支持很多协议,包括传输层的TCP.UDP.TLS,以及应用层的HTTP.FTP等.对所有这些协议,T ...