对于交换行、交换列的操作,分别记录当前状态下每一行、每一列是原始数组的哪一行、哪一列即可。

对每一行、每一列加一个数的操作,也可以两个数组分别记录。注意当交换行、列的同时,也要交换增量数组。

输出时通过索引找到原矩阵中的值,再加上行、列的增量。

复杂度O(q+mn)

#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
using namespace std;
#define INF 0x3f3f3f3f
#define N 1010
int a[N][N];
int ans[N][N]; int xh[N],h[N];
int xl[N],l[N]; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int q,n,m;
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
}
memset(xh,0,sizeof(xh));
memset(xl,0,sizeof(xl));
for(int i=1;i<=n;i++)
h[i]=i;
for(int i=1;i<=m;i++)
l[i]=i;
int k,x,y;
for(int i=0;i<q;i++)
{
scanf("%d%d%d",&k,&x,&y);
if(k==1)
{
int t=h[x];
h[x]=h[y];
h[y]=t;
}
else if(k==2)
{
int t=l[x];
l[x]=l[y];
l[y]=t;
}
else if(k==3)
{
xh[h[x]]+=y;
}
else if(k==4)
{
xl[l[x]]+=y;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
ans[i][j]=a[h[i]][l[j]]+xh[h[i]]+xl[l[j]];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(j!=1)
printf(" ");
printf("%d",ans[i][j]);
}
printf("\n");
}
}
return 0;
}

hdoj5671 BestCoder Round #81 (div.2)的更多相关文章

  1. BestCoder Round #81 (div.2) 1004 String(动态规划)

    题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...

  2. BestCoder Round #81 (div.2) 1003 String

    题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...

  3. BestCoder Round #81 (div.2)C String

    总体思路好想,就是在找K个不同字母的时候,卡时间. 看了大神代码,发现goto的!!!!998ms #include<cstdio> #include<cstring> #in ...

  4. BestCoder Round #81 (div.2) B Matrix

    B题...水题,记录当前行是由原矩阵哪行变来的. #include<cstdio> #include<cstring> #include<cstdlib> #inc ...

  5. BestCoder Round #81 (div.1)A

    水题...就是n的三进制后m位 #include<cstdio> #include<cstring> #include<cstdlib> #include<i ...

  6. BestCoder Round #81 (div.2)1001

    Machine Accepts: 580 Submissions: 1890 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...

  7. BestCoder Round #81 (div.2)

    HDU:5670~5764 A题: 是一个3进制计数: #include <bits/stdc++.h> using namespace std; ]; int calc(long lon ...

  8. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  9. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

随机推荐

  1. Solidworks如何绘制标准螺纹线

    1 绘制螺旋线,螺距为0.5mm,圈数为15,起始角度为0°.   2                

  2. ActiveMQ(六) 转

    package pfs.y2017.m11.mq.activemq.demo07; import org.apache.activemq.ActiveMQConnectionFactory; impo ...

  3. Linux input子系统实例分析(二)

    紧接着上一节的实例我们来分析调用的input子系统的接口: 1. input_dev,用来标识输入设备 1: struct input_dev { 2: const char *name; //设备名 ...

  4. 持续集成-jenkins 环境搭建

    转自:http://blog.jxdev.me/blog/2015/03/26/jian-xin-de-chi-xu-ji-cheng-zhi-lu-%5B%3F%5D-da-jian-jenkins ...

  5. const& 的东西

    class_name ( class_name const & source ); 是拷贝构造函数的标准声明. 它和如下声明是一个意思 class_name ( const class_nam ...

  6. thinkphp Class 'PDO' not found 错误

    thinkphp Class 'PDO' not found 错误,原因mysql5.7.26缺少pdo驱动,需要安装php的pdo和pdo_mysql扩展 本文以centOS为例 1.进入PHP源码 ...

  7. Scaling with Microservices and Vertical Decomposition

    Scaling with Microservices and Vertical Decomposition – dev.otto.de https://dev.otto.de/2014/07/29/s ...

  8. 搭建双系统后没有windows的引导程序

    因为安装linux系统前没有安装引导程序,导致安装了linux系统后进入linux系统没有windows的引导程序,网上找了很多解决办法,也不能说是不好使,只是作为新手小白来说有点难以理解,最后无意中 ...

  9. redis03----link 链表操作

    link 链表结构 之前是操作字符串string 链表:头元素,后面一个一个的指向后面的元素.Redis内部实现了链表的结构.链表的头尾,从一个元素找到另外的元素. 链表的名字也是一个key. flu ...

  10. mysql优化-----索引覆盖

    一道面试题: 有商品表, 有主键,goods_id, 栏目列 cat_id, 价格price 说:在价格列上已经加了索引,但按价格查询还是很慢,问可能是什么原因,怎么解决? 答:在实际场景中,一个电商 ...