思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   。

r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j 列 存的是原先的哪列。

查询只需要一个二分即可。

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define MAXN 100050
using namespace std;
int r[MAXN], c[MAXN];
struct info {
int x, y, z;
} s[MAXN];
struct node {
int va;
int col;
};
bool operator<(node a, node b) {
return a.col < b.col;
}
vector<node> e[MAXN];
int qr[MAXN];
int qc[MAXN];
int main() {
int cntr, cntc, tt, ri = ;
scanf("%d", &tt);
while (tt--) {
int n, m, k, tailr, tailc;
tailr = tailc = ;
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i < k; ++i) {
scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].z);
qr[tailr++] = s[i].x;
qc[tailc++] = s[i].y;
}
sort(qr,qr+tailr);
sort(qc,qc+tailc);
tailr = unique(qr, qr + tailr) - qr;
tailc = unique(qc, qc + tailc) - qc;
for (int i = ; i < tailr; ++i)
e[i].clear();
for (int i = ; i < k; ++i) {
int x = lower_bound(qr, qr + tailr, s[i].x) - qr;
int y = lower_bound(qc, qc + tailc, s[i].y) - qc;
node d;
d.col = y;
d.va = s[i].z;
e[x].push_back(d);
}
for (int i = ; i < tailr; ++i)
sort(e[i].begin(), e[i].end());
for (int i = ; i < tailr; ++i)
r[i] = i;
for (int i = ; i < tailc; ++i)
c[i] = i;
printf("Case #%d:\n", ++ri);
int T;
scanf("%d", &T);
while (T--) {
int x, a, b;
scanf("%d%d%d", &x, &a, &b);
if (x == ) {
int idr = lower_bound(qr, qr + tailr, a) - qr;
if (qr[idr] != a)
continue;
int idc = lower_bound(qr, qr + tailr, b) - qr;
if (qr[idc] != b)
continue;
swap(r[idr], r[idc]);
}
if (x == ) {
int idr = lower_bound(qc, qc + tailc, a) - qc;
if (qc[idr] != a)
continue;
int idc = lower_bound(qc, qc + tailc, b) - qc;
if (qc[idc] != b)
continue;
swap(c[idr], c[idc]);
}
if (x == ) {
int idr = lower_bound(qr, qr + tailr, a) - qr;
if (qr[idr] != a)
{
puts("");
continue;
}
int idc = lower_bound(qc, qc + tailc, b) - qc;
if (qc[idc] != b)
{
puts("");
continue;
}
node cc;
cc.col=c[idc];
vector<node>::iterator it=lower_bound(e[r[idr]].begin(),e[r[idr]].end(),cc);
if(it==e[r[idr]].end())
{
puts("");
continue;
}
node d=*(it);
if(d.col!=c[idc])
{
puts("");
continue;
}
printf("%d\n",d.va);
}
}
}
return ;
}

HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)的更多相关文章

  1. hdu 4941 Magical Forest

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...

  2. STL : map函数的运用 --- hdu 4941 : Magical Forest

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  3. hdu 4941 Magical Forest (map容器)

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  4. HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...

  5. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

  6. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  7. hdu 4941 Magical Forest ( 双重map )

    题目链接 题意: 有一个n*m的田地,里边有k棵树,每棵树的位置为(xi,yi),含有能量值ci.之后又q个询问,分三种; 1)1 a b,将a行和b行交换 2)2 a b,将a列和b列交换 3)3 ...

  8. HDU 4941 Magical Forest (Hash)

    这个题比赛的时候是乱搞的,比赛结束之后学长说是映射+hash才恍然大悟.因此决定好好学一下hash. 题意: M*N的格子,里面有一些格子里面有一个值. 有三种操作: 1.交换两行的值. 2.交换两列 ...

  9. HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5

    思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...

随机推荐

  1. iOS UIButton 设置图片不变型setImage

    [btn.imageView setContentMode:UIViewContentModeScaleAspectFill];

  2. 续并查集学习笔记——Closing the farm题解

    在很多时候,并查集并不是一个完整的解题方法,而是一种思路. 通过以下题目来体会并查集逆向运用的思想. Description Farmer John and his cows are planning ...

  3. 工作上遇到的问题 DEBUG 001

    java文件断点跳到对应的class文件解决方式 我也是第一次遇到这个问题,找了很久解决办法.后面找开发组老大才解决. 问题描述: 调试程序,在ExportAction.java文件打断点.debug ...

  4. mysql导入乱码问题,centOS

    CREATE DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;mysql -uroot -p --default ...

  5. matplotlib绘制动画

    matplotlib从1.1.0版本以后就开始支持绘制动画,具体使用可以参考官方帮助文档.下面是一个很基本的例子: """ A simple example of an ...

  6. virtualbox安装增强功能时【未能加载虚拟光盘】

    virtualbox安装增强功能时[未能加载虚拟光盘] 今天在使用Virtualbox中的Ubuntu虚拟机,想安装增强功能来实现更改分辨率,但是在安装时出错:未能加载虚拟光驱 VBoxsGuestA ...

  7. Mac系统下配置Tomcat

    1.下载Tomcat,网址:http://tomcat.apache.org/download-70.cgi: 2.进入终端Terminal,打开配置文件.bash_profile,输入open .b ...

  8. an interview question(2)

    感觉现在好多面试题还是很注重基础的,今天面试时就遇到这题,回来一查后才知道此题是国内某著名通信公司的一道机试题:) 给定一个数组input[ ],如果数组长度n为奇数,则将数组中最大的元素放到 out ...

  9. 为什么不要使用Response.Close()

    不要使用Response.Close()    不要使用Response.Close()    不要使用Response.Close()        1  因为:Close()方法会调用HttpWo ...

  10. spring定时器,当遇见半小时的情况时

    spring定时器遇见半小时的解决方法(这里只提供注解方式) @Scheduled(fixedRate=6000000)//每隔100分钟执行方法 fixedRate的值是毫秒