题目链接:http://codeforces.com/contest/878/problem/D

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 k creatures numbered from 1to 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 41 22 11 1 22 1 23 3 13 4 2

output

Copy

21

input

Copy

5 3 81 2 3 4 55 1 2 3 44 5 1 2 31 1 21 2 32 4 53 6 13 6 23 6 33 6 43 6 5

output

Copy

52234

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

思路:先看一下简单情况,假如属性只有0和1的情况,那么取大的是不是就是或操作呢‘? 取小的是不是就是与操作呢?  显然是的

但是你可能会说 问题是属性值不是1和0啊   是的,我也这么想。 怎么用0和1表示出来呢? 想想,是不是不管你怎么操作,最后出来的答案一定是原本有的怪兽演变过来的?

想到这就好点了,那么也就是说,加入我们可以知道新得到的怪兽是通过哪几个怪兽演变过来的就好了。

状态压缩,最多有12种怪兽,所以最多的情况是1<<12种情况,我们把首先每种怪兽可能属于的情况存起来  比如怪兽1  那么它可能属于的情况就是  ***********中第一位为1  其它随便怎么

组合。  这样存起来之后,每种怪兽刚开始可能的情况就存起来了  接下来是操作,假如是操作1  那么还是或操作   假如是操作2  那么还是与操作

假如是操作3  我们先把属性和对应的下标存起来  按照属性值排序   得到的第一个满足条件的值就是答案了。

代码:

#include<iostream>
#include<cstdio>
#include<bitset>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
const LL mod=998244353;
int a[15][maxn];bitset<4096> s[maxn];//1<<12=4096
int main()
{int N,M,Q;scanf("%d%d%d",&N,&M,&Q);for(int i=1;i<=M;i++){for(int j=1;j<=N;j++){scanf("%d",&a[i][j]);}}
//    for(int i=1;i<=M;i++)
//    {
//        for(int j=1;j<=N;j++)
//        {
//            cout<<a[i][j]<<" ";
//        }
//        cout<<endl;
//    }for(int i=1;i<4096;i++){for(int j=1;j<=M;j++){if(i&(1<<(j-1))) s[j].set(i);}}
//    for(int i=1;i<=M;i++) cout<<s[i]<<endl;int tot=M+1;for(int i=1;i<=Q;i++){int t,x,y;scanf("%d%d%d",&t,&x,&y);if(t==1) s[tot++]=s[x]|s[y];else if(t==2) s[tot++]=s[x]&s[y];else{vector<pair<int,int> >v;for(int j=1;j<=M;j++) v.push_back({a[j][y],j});sort(v.begin(),v.end(),greater<pair<int,int> >());
//            for(int j=0;j<M;j++) cout<<v[j].first<<" "<<v[j].second<<endl;int b=0;for(int j=0;j<M;j++){b|=(1<<(v[j].second-1));
//                cout<<"b:"<<b<<endl;if(s[x][b]){printf("%d\n",a[v[j].second][y]);break;}}}}return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/10859185.html

D. Magic Breeding相关推荐

  1. CodeForces 878 简要题解

    A. Short Program 起床困难综合征,随便构造一下就好了. #include <bits/stdc++.h> #define xx first #define yy secon ...

  2. Educational Codeforces Round 9 F. Magic Matrix 最小生成树

    F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a mat ...

  3. 我花了三个小时写了一道题的六千字题解....(POJ 2888 Magic Bracelet)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 前置知识:小学生都能看懂的群论从入门到升天教程 <群论全家桶> 一道简单的题目 Probl ...

  4. 安装报错_RG Magic Bullet安装报错修复方法

    RG Magic Bullet安装报错修复方法 安装和谐版红巨星插件发现有很大的概率报错.这几天重装电脑被这个插件搞得头大.网上查了一些排除错误的方法,基本错误可以靠删除一些重复的文件夹和老版本来修复 ...

  5. magic系统将来能升鸿蒙,荣耀30和V30将首批搭载Magic UI 4.0 后续可升级鸿蒙系统

    腾讯科技讯 9月10日下午15点30分,华为消费者业务软件部总裁王成录在华为开发者大会上发表了题为<连接无限可能-全场景终端软件发布>的主题演讲,EMUI 11和Magic UI 4.0同 ...

  6. 全球首个Magic Leap One体验:吓到你不敢进房间

    来源:智东西 概要:业内备受关注的AR技术公司Magic Leap,在获得19亿美元融资历经七年之后,终于放出其第一款头盔产品Magic Leap One,很快在科技圈.VR圈引起刷屏式关注. 昨夜, ...

  7. 吊打Magic Leap,微软HoloLens 2不只为炫技

    近几日网上关于HoloLens 2的话题颇多.Infinite Retina联合创始人,拥有40多万关注者的Robert Scoble发推写道,HoloLens 2一出,Magic Leap就没那么& ...

  8. 新产品扑朔迷离,Magic Leap又跑去收购3D扫描公司

    Magic Leap收购Dacuda的3D扫描资产,很可能是为了解决其产品的位置追踪问题. 对于神秘的AR公司Magic Leap来说,他们的一举一动都会成为科技圈的头条,上周被外媒曝出产品原型机,不 ...

  9. 终于要揭开神秘面纱?Magic Leap将要展示产品

    Magic Leap准备下周召开董事会,并且会在会议上展示Magic Leap的原型机 "PEQ ". 自打去年年底被爆出产品无法小型化的问题之后,Magic Leap沉寂了一段时 ...

最新文章

  1. 我们该使用哪种分布式锁?
  2. 犹豫了许久,还是写个年总结记录一下吧
  3. Ubuntu安装搜狗输入法Linux版
  4. CUDA编程指南阅读笔记
  5. 第7章:项目成本管理习题总结
  6. asp.net webapi 自定义身份验证
  7. SAP WebIDE:how to enable context API reference
  8. 什么是 DDoS 攻击?
  9. Gartner 企业级网络设备市场份额报告:阿里云负载均衡增速全球第一
  10. trackingmore快递查询平台_快递物流服务再升级!寄快递更便捷,看看都有哪些平台...
  11. mysql数据库加载太慢_使用MySQL数据库很慢
  12. 破解版的ABBYY FineReader OCR文字识别软件,真的好用吗?
  13. Hbase 查询命令 条件筛选
  14. hive 漫威the_2021年即将上映的漫威电影
  15. 打砖块android代码,打砖块游戏的源代码
  16. 新猿木子李:0基础学python培训教程 Python操作Redis之有序集合
  17. spring入参为指定值,校验java入参的值为规定的值,利用Validator指定值校验注解——一看就会
  18. cm11修改wifi_mac地址
  19. 计算机程序设计c++ 9-7:类的抽象描述举例-汽车类及圆类设计
  20. Java获取package下所有的class对象(普通文件包和Jar文件包)

热门文章

  1. Css兼容:如何解决IE7和IE8的BUG
  2. 关于在CVS下无法获取更新的解决方法!!!
  3. vs2015打开慢的解决方法
  4. python 3.6.3 异常
  5. Eclipse导入maven项目报Resources文件夹红叉问题解决方案
  6. 解决Matlab画图直接保存.eps格式而导致图不全的问题
  7. 【报告分享】中国零售业公私域运营手册暨实施指引.pdf(附下载链接)
  8. 【实践】图推荐算法在EE问题上的应用(附交流视频和PPT下载链接)
  9. 【招聘内推】阿里巴巴广告/推荐/搜索-算法工程师岗位
  10. jvm入门到详解-1