思路:将行列离散化,那么就可以用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. HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容

    今天把一个.NET的网站部署到IIS上打开网页的时候出现了这个错误,刚开始以为是没有配置默认页,但是直接打开固定的页面地址也不行. 于是怀疑是.NET版本的问题,但是看了一下程序的目标框架是4.0没错 ...

  2. test lab ~ triangle test by using junit and coverage

    first set up a new folder as your test class place, and then let your package in test class folder b ...

  3. centos 怎么安装 g++

    centos 怎么安装 g++ 找了n久  找到一个实用的 有gcc  但是 是老版本的  tarball 编译 nmap 的时候说机器没有g++ 各种方法都试过 然后 找到下面这个方法: cento ...

  4. 01 ~ 03 headfirst php & mysql

    Question : 难道不是所有web页面原先都放在服务器上吗? 甚至存储在.html文件中的HTML页面? Answer : 没错, 网站的所有文件都存储在服务器上, html, css, php ...

  5. Table样式

    .tb_org th { background-color: #; color: #ffffff; } .tb_org { border-right: 1px solid silver; border ...

  6. aspx页面常用代码

    Response.Redirect(Request.Url.ToString());//刷新页面 Response.Write("<script>alert('有数据尚未添加') ...

  7. sim800 gprs发送数据的AT流程

    switch(send_flag) { case 1: uart_send(&huart4,"AT\r\n",4); //AT break; case 2: uart_se ...

  8. SAP 设置屏幕字段的隐藏、显示、必填和可选,以设置物料组为例

    1.事务码MM01,把物料组设为选填字段. 2.找到物料组的屏幕字段. 3.在后台根据屏幕字段找到对应字段组.后台路径:后勤-常规—物料主数据—字段选择—给字段组分配字段.点击后面的箭头进入下一屏幕. ...

  9. e.Tomcat中的sendfile支持

    sendfile实质是linux系统中一项优化技术,用以发送文件和网络通信时,减少用户态空间与磁盘倒换数据,而直接在内核级做数据拷贝,这项技术是linux2.4之后就有的,现在已经很普遍的用在了C的网 ...

  10. Excel公式学习

    1.Left函数 (1)语法格式=left(text,num_chars) ,(text代表用来截取的单元格内容,num_chars代表从左开始截取的字符数): (2)示例:例如A1单元格内的文本为: ...