【POJ】2155 Matrix

二维树状数组。

复制代码
 1 /* poj2155 */
 2 #include <iostream>
 3 #include <string>
 4 #include <map>
 5 #include <queue>
 6 #include <vector>
 7 #include <algorithm>
 8 #include <cstdio>
 9 #include <cmath>
10 #include <cstring>
11 #include <climits>
12 #include <cctype>
13 using namespace std;
14 
15 #define MAXN 1005
16 
17 bool cnt[MAXN][MAXN];
18 int n, m;
19 
20 inline int lowest(int x) {
21     return x&-x;
22 }
23 
24 int sum(int x1, int y1) {
25     int i, j, k;
26     int ret = 0;
27     
28     for (i=x1; i; i-=lowest(i))
29         for (j=y1; j; j-=lowest(j))
30             ret += cnt[i][j];
31     return ret&1;
32 }
33 
34 void update(int x1, int y1) {
35     int i, j, k;
36     
37     for (i=x1; i<=n; i+=lowest(i))
38         for (j=y1; j<=n; j+=lowest(j))
39             cnt[i][j] = !cnt[i][j];
40 }
41 
42 int main() {
43     int t;
44     int i, j, k;
45     int x1, y1, x2, y2;
46     char s[3];
47     
48     #ifndef ONLINE_JUDGE
49         freopen("data.in", "r", stdin);
50         freopen("data.out", "w", stdout);
51     #endif
52     
53     scanf("%d", &t);
54     while (t--) {
55         scanf("%d %d", &n, &m);
56         memset(cnt, false, sizeof(cnt));
57         while (m--) {
58             scanf("%s", s);
59             if (s[0] == 'Q') {
60                 scanf("%d %d", &x1, &y1);
61                 k = sum(x1, y1);
62                 if (k)
63                     puts("1");
64                 else
65                     puts("0");
66             } else {
67                 scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
68                 update(x1, y1);
69                 update(x1, y2+1);
70                 update(x2+1, y1);
71                 update(x2+1, y2+1);
72             }
73         }
74         if (t)
75             putchar('\n');
76     }
77     
78     return 0;
79 }
复制代码

 

posted on   Bombe  阅读(131)  评论(0编辑  收藏  举报

编辑推荐:
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
阅读排行:
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· 大模型工具KTransformer的安装
· [计算机/硬件/GPU] 显卡
历史上的今天:
2014-03-24 【原创翻译】Reducing Branch Delay to Zero in Pipelined Processors
2014-03-24 【算法导论】学习笔记——第22章 图的基本算法
2014-03-24 【HDOJ】1253 胜利大逃亡
2014-03-24 【Python】代码行数统计
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示