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 ...
随机推荐
- uvm_reg_backdoor——寄存器模型(十)
寄存器有前门和后门两种访问方式,这儿只看后门访问方式 //----------------------------------------------------------------------- ...
- HDU Rabbit and Grass 兔子和草 (Nim博弈)
思路:简单Nim博弈,只需要将所给的数字全部进行异或,结果为0,则先手必败.否则必胜. #include <iostream> using namespace std; int main( ...
- JS实现单向链表、双向链表、循环链表
https://cloud.tencent.com/developer/article/1114246 链表存储有序的元素的集合,但是和数组不同的是,链表中的元素在内存中的存储并不是连续的.每一个链表 ...
- 2018.5.6 解决问题:oracle------ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务
解决问题:ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 或者是重启电脑之后无法进入控制台企业管理器(OEM)图形化界面(重新添加注入监听器就行了 文件listener.org) ...
- python处理图片的一些操作
1.把图片分割成一个个竖条: from PIL import Image gap = 20 img_name = '/home/sensetime/000132_11_4.png' im = Imag ...
- Python中文编码问题(字符串前面加'u')
中文编码问题是用中文的程序员经常头大的问题,在python下也是如此,那么应该怎么理解和解决python的编码问题呢? 我们要知道python内部使用的是unicode编码,而外部却要面对千奇百怪的各 ...
- Bootstrap历练实例:堆叠的进度条
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- Java 练习:字符串反转
package com.swift; public class String_Reverse_Test { public static void main(String[] args) { /* * ...
- [Codeforces Round #250]小朋友和二叉树
题目描述: bzoj luogu 题解: 生成函数ntt. 显然这种二叉树应该暴力薅掉树根然后分裂成两棵子树. 所以$f(x)= \sum_{i \in c} \sum _{j=0}^{x-c} f( ...
- 【线性基合并 树链剖分】bzoj4568: [Scoi2016]幸运数字
板子题 Description A 国共有 n 座城市,这些城市由 n-1 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有一个 幸运数字,以纪念碑的形式矗立在这座城市的正中心,作为城市 ...