【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 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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】代码行数统计