思路:将行列离散化,那么就可以用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. 28-React state提升、组件组合或继承

    Lifting State Up state提升 对于在React应用程序中更改的任何数据,应该有一个单一的数据源.通常,都是将state添加到需要渲染的组件.如果其他组件也需要它,您可以将其提升到最 ...

  2. 什么是hasLayout?

    想更好的理解CSS,尤其是IE下对CSS的渲染,hasLayout是一个非常有必要彻底弄清楚的概念,大多数IE下的显示错误,就是源于hasLayout.hasLayout是一种只读属性,有两种状态tr ...

  3. 图解说明——究竟什么是Windows句柄

    图解说明——究竟什么是Windows句柄 参考资料:http://blog.csdn.net/newjerryj/article/details/4383701 http://www.cnblogs. ...

  4. 如何隐藏winform中报表设计器中的按钮

    https://www.devexpress.com/Support/Center/Question/Details/T246117 DesignMdiController.SetCommandVis ...

  5. iOS 消息推送报错NSCocoaErrorDomain Code=3000

    转自: http://www.cnblogs.com/zxykit/p/5207498.html Xcode7推送报错.Error Domain=NSCocoaErrorDomain Code=300 ...

  6. JavaScript中有关数字的精确计算

    问题这样的: 37.5*5.5=206.08 (JS算出来是这样的一个结果,我四舍五入取两位小数) ,我先怀疑是四舍五入的问题,就直接用JS算了一个结果为:206.08499999999998 怎么会 ...

  7. zend studio 10破解/汉化

    http://blog.csdn.net/qq1355541448/article/details/16807429

  8. stm32cube--ADC单次转换

    stm32cube的ADC配置 ① ② ③ ④ ⑤ 二:用到的函数 HAL_StatusTypeDef       HAL_ADCEx_Calibration_Start(ADC_HandleType ...

  9. html的a链接的href怎样才另起一个页面

    在后面加上target ="_blank",就可以,正如: <ul class="nav navbar-nav navbar-right" style=& ...

  10. Sudoku 数独游戏

    #include<iostream> using namespace std; bool heng(int **sudo, int a, int b, int value) { bool ...