题意:

给出一个矩阵,有两种操作:

1.翻转给定的子矩阵;

2.查询a[i][j]的值。

思路:

树状数组是从小到大更新的。

这个题用二维树状数组可以解决,假设是一维树状数组,

0 0 0 0 0 0

我们把第三个到第四个翻转,变成

0 0 1 1 -1 0

sum[1] = 0,sum[2] = 0,sum[3] = 1,sum[4] = 1,sum[5] = 0,sum[6] = 0

所以类似一维的bit,但是要用到容斥原理,多减的要加回来。

代码:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5. const int N = ;
  6. int c[N][N];
  7. int n;
  8. int lowbit(int x)
  9. {
  10. return x&(-x);
  11. }
  12. void add(int x,int y)
  13. {
  14. for (int i = x;i <= n;i += lowbit(i))
  15. {
  16. for (int j = y;j <= n;j += lowbit(j))
  17. {
  18. c[i][j] += ;
  19. }
  20. }
  21. }
  22. int getsum(int x,int y)
  23. {
  24. int ans = ;
  25. for (int i = x;i > ;i -= lowbit(i))
  26. {
  27. for (int j = y;j > ;j -= lowbit(j))
  28. {
  29. ans += c[i][j];
  30. }
  31. }
  32. return ans;
  33. }
  34. int main()
  35. {
  36. int T;
  37. scanf("%d",&T);
  38. while (T--)
  39. {
  40. int op;
  41. scanf("%d%d",&n,&op);
  42. memset(c,,sizeof(c));
  43. while (op--)
  44. {
  45. char s[];
  46. scanf("%s",s);
  47. if (s[] == 'C')
  48. {
  49. int x1,y1,x2,y2;
  50. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  51. add(x1,y1);
  52. add(x2 + ,y1);
  53. add(x1,y2 + );
  54. add(x2 + ,y2 + );
  55. }
  56. if (s[] == 'Q')
  57. {
  58. int x,y;
  59. scanf("%d%d",&x,&y);
  60. int ans = getsum(x,y);
  61. if (ans % ) puts("");
  62. else puts("");
  63. }
  64. }
  65. if (T) puts("");
  66. }
  67. return ;
  68. }

poj 2115 Matrix的更多相关文章

  1. POJ 2115 C Looooops(扩展欧几里得应用)

    题目地址:POJ 2115 水题. . 公式非常好推.最直接的公式就是a+n*c==b+m*2^k.然后能够变形为模线性方程的样子,就是 n*c+m*2^k==b-a.即求n*c==(b-a)mod( ...

  2. POJ poj 2155 Matrix

    题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...

  3. 【题解】POJ 2115 C Looooops (Exgcd)

    POJ 2115:http://poj.org/problem?id=2115 思路 设循环T次 则要满足A≡(B+CT)(mod 2k) 可得 A=B+CT+m*2k 移项得C*T+2k*m=B-A ...

  4. 矩阵十点【两】 poj 1575 Tr A poj 3233 Matrix Power Series

    poj 1575  Tr A 主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 题目大意:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的 ...

  5. POJ 2155 Matrix

    二维树状数组....                          Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  6. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  7. POJ 2155 Matrix (二维线段树)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

  8. poj 3685 Matrix(二分搜索之查找第k大的值)

    Description Given a N × N matrix A, whose element × i + j2 - × j + i × j, you are to find the M-th s ...

  9. POJ 2155 Matrix (D区段树)

    http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 1 ...

随机推荐

  1. python3 配置logging日志类

    配置类config_file: from configparser import ConfigParser class config_file: def __init__(self,conf_file ...

  2. django——CRM项目

    1.引言 CRM,客户关系管理系统(Customer Relationship Management).企业用CRM技术来管理与客户之间的关系,以求提升企业成功的管理方式,其目的是协助企业管理销售循环 ...

  3. GMA Round 1 新程序

    传送门 新程序 程序框图如图所示,当输入的n=时,输出结果的ans是多少? 容易看出该程序求n以内质数个数,50以内有15个. 定位:简单题

  4. P1316 丢瓶盖--(二分答案)

    题目描述 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想从这些瓶盖里找出B个,使得距离最近的2个距离最大,他想知道,最大可以到多少呢? 输入输出 ...

  5. duilib 新增数据迁移界面

    xml界面配置: <?xml version="1.0" encoding="utf-8"?> <Window caption="0 ...

  6. CentOS7 安装 jexus-5.8.2-x64

    前要提示: 如果你要安装asp.net 请参考: http://www.cnblogs.com/xiaoruilin/p/7867823.html 背景: CentOS7 Mono (Mono JIT ...

  7. convert(varchar(10),字段名,转换格式

    sql 时间转换格式 ) convert(varchar(10),字段名,转换格式) CONVERT(nvarchar(10),count_time,121)CONVERT为日期转换函数,一般就是在时 ...

  8. Java+面向对象初学感想

    在先导课之前我未曾接触C和Python之外的语言,在大一学年的课程中,用面向过程的思想方法足以完成绝大多数课程要求,故而我也对面向对象的编程思想知之甚少,虽然多有耳闻但是对它一直没有一个正式的学习了解 ...

  9. [daily][archlinux] TODO LIST

    reminder: https://wikemacs.org/wiki/Buffer_management TO READ: https://www.kernel.org/doc/htmldocs/k ...

  10. HTML技巧篇:如何让单行文本以及多行文本溢出时显示省略号(…)

    参考:https://baijiahao.baidu.com/s?id=1621362934713048315&wfr=spider&for=pc 本篇文章主要给大家介绍一下在html ...