POJ 2155 二维线段树【线段树套线段树】
来源:互联网 发布:wine for mac下载 编辑:程序博客网 时间:2024/06/05 17:22
题目大意:
二维区间里,某个矩形里都是01, 选一个矩形,里面数字01翻转。
最后不停的问某个坐标是0还是1.
POJ不支持C++!1所以常用头文件要注释掉很多……
大致二维线段树就是这样的了……
每个节点都是一个线段树。
QC大爷说二维线段树不支持打标记。好像这题也不用打标记了,只能标记永久化
//#include <bits/stdc++.h>//#include <ext/pb_ds/priority_queue.hpp>//#include <tr1/unordered_map>//#include <ctime>//using std::tr1::unordered_map;#include <iostream>#include <cstring>#include <queue>#include <algorithm>#include <cstdio>using std::sort;//using std::bitset;using std::max;using std::cout;//using std::stack;using std::cin;using std::endl;using std::swap;//using std::pair;//using std::vector;//using std::set;//using std::map;//using std::multiset;//using std::queue;using std::greater;using std::string;//using std::priority_queue;//using std::max_element;//using std::min_element;//using __gnu_pbds::pairing_heap_tag;//__gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> heap;#define Hash unordered_map#define pr(x) cout<<#x<<" = "<<x<<" "#define prln(x) cout<<#x<<" = "<<x<<endl#define lson o*2, L, M#define rson o*2+1, M + 1,Rint cov[4001][4001];int n, m;int xql, xqr, yql, yqr;void init(){scanf("%d%d", &n, &m);memset(cov, 0, sizeof(cov));}void y_update(int k, int o, int L, int R){if (yql <= L && R <= yqr){cov[k][o] ^= 1;return;}int M = L + (R-L)/2;if (yql <= M)y_update(k, lson);if (yqr > M)y_update(k, rson);}void x_update(int o, int L, int R){//cout<<o<<" "<<L<<" "<<R<<" "<<xql<<" "<<xqr<<endl;if (xql <= L && R <=xqr){y_update(o, 1, 1, n);return;}int M = L + (R - L)/2;if (xql <= M)x_update(lson);if (xqr > M)x_update(rson);}int ans;int qx, qy;void y_query(int k, int o, int L, int R){ans ^= cov[k][o];//if (qy <= L && R <= qy)if (L ==R){return;}int M = L + (R - L)/2;if (qy <= M)y_query(k, lson);else y_query(k, rson);}void x_query(int o, int L, int R){y_query(o, 1, 1, n);//if (qx <= L && R<=qx)if (L==R){return;}int M = L + (R - L)/2;if (qx <= M)x_query(lson);else x_query(rson);}void doit(){while (m--){char flag;//prln(flag);getchar();scanf("%c", &flag);//prln(flag);if (flag=='C'){scanf("%d%d%d%d", &xql, &yql, &xqr, &yqr);//cout<<xql<<" "<<xqr<<" "<<yql<<" "<<yqr<<endl;x_update(1, 1, n);//cout<<flag<<" "<<xql<<" "<<xqr<<" "<<yql<<" "<<yqr<<endl;}else{scanf("%d%d", &qx, &qy);ans = 0;x_query(1, 1, n);printf("%d\n", ans);//cout<<flag<<" "<<qx<<" "<<qy<<endl;}}}int main(){int T;scanf("%d", &T);int sb=0;while (T--){if (sb)printf("\n");++sb;init();doit();}return 0;}
0 0
- POJ 2155 二维线段树【线段树套线段树】
- POJ 2155 二维线段树
- POJ 2155 二维线段树
- poj 2155 二维线段树
- POJ 2155 树套树—线段树套线段树
- 线段树套Treap
- POJ 2155 二维线段树 书套树
- 二维线段树 POJ 2155 Matrix
- POJ 2155(二维zkw线段树)
- POJ 2155 Matrix 二维线段树
- POJ 2155 Matrix【二维线段树】
- POJ 2155 Matrix (二维线段树)
- poj 2155 二维线段树/树状数组
- poj 2155 二维线段树 插线问点
- POJ 2155 Matrix 二维线段树
- POJ 2155 Matrix (二维线段树)
- POJ 2155 二维线段树基本操作
- poj 2155 Matrix 【二维线段树】
- 关闭cassandra 或者 tomcat 的方式
- UVA10878 Decode the tape
- 恶意代码--windows脚本wscript恶意样本逆向分析
- Codeforces Round #367 (Div. 2) C
- CSS checkbox
- POJ 2155 二维线段树【线段树套线段树】
- object与byte[]的相互转换、文件与byte数组相互转换
- Android概述
- [转]如何在Ubuntu 14.04中安装最新版Eclipse
- dijkstra求最短路径长度
- Win10 多用户远程登录成功实然无法远程的问题
- [floyd]poj1125 Stockbroker Grapevine
- Hibernate的java.lang.StackOverFlowError问题
- 51nod 矩阵取数问题