本来是想找一个二维线段树涉及懒惰标记的,一看这个题,区间修改,单点查询,以为是懒惰标记,敲到一半发现这二维线段树就不适合懒惰标记,你更新了某段的某列,但其实其他段的相应列也要打标记,但因为区间不一样,又不好打...也可能是我这是在套用一维线段树的思想,还有更好的二维线段树懒惰标记方法 反正到现在我还没搞定二维线段树的懒惰标记,因为这道题不用懒惰标记,因为是二进制序列,区间修改仅限于翻转操作,那就只要记录每次操作,最后查询的时候从上往下把所有修改都来上一遍,就可以了.就类似于树状数组的第二种用法,…
题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<stdlib.h> using namespace std; #define ll long long #define re(i,n) for(int i=0;i<n;i++) ; int c[maxn][maxn]; int n, q; int lowbit(int x){ return x&…
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <map> #include <set> #include <stack> #define mp make_pair #define pa pair<int,int> #define pb p…
题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维线段树 简单来说就是每个点都维护了一颗线段树... 因为二维线段树难以实现pushdown,而他的查找又是单点的 于是具体思路类似标记永久化,记录经过的点上的修改次数,最后判断修改次数的奇偶性即可 //为什么不写构造函数和vector? //因为这是神奇的poj... #include<iostre…
1: #include <stdio.h> 2: #include <string.h> 3: #include <stdlib.h> 4: #include <algorithm> 5: #include <iostream> 6: using namespace std; 7:   8: #define LL(a) a<<1 9: #define RR(a) a<<1|1 10: const int MaxL = 10…
可以发现这个写挂的树状数组求的是后缀和.find(r)-find(l-1)在模2意义下实际上查询的是l-1~r-1的和,而本来要查询的是l~r的和.也就是说,若结果正确,则a[l-1]=a[r](mod 2). 一个很容易想到的思路是线段树维护每一位为1的概率.然而这其实是不对的,因为每一位是否为1并非独立事件. 世界上没有什么事情是用一维线段树解决不了的,如果有,那就两维 我们维护每两位之间相同的概率.考虑一次操作对某两位的影响.若该次操作包含两位中的x位,那么改变两者间相同状态的概率就是x/…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1…
题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn.net/xiamiwage/article/details/8030273 思路: 二维线段树,一维线段树的成段更新需要lazy. 引申到二维线段树应该需要一个lazy,一个sublazy,可是这里什么都不用.    奇妙之处在于这题的操作是异或,当某一段区间需要异或操作时候, 不必更新到它所有的…
题目大意:给你一个全是0的N*N矩阵,每次有两种操作:1将矩阵中一个子矩阵置反,2.查询某个点是0还是1 思路:裸的二维线段树 #include<iostream>#include<cstdio>#include <math.h>#include<algorithm>#include<string.h>#include<queue>#define MOD 1000003#define maxn 4009#define LL long…
Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 Description Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The…
链接http://poj.org/problem?id=2155 题目操作就是说,每次操作可以是编辑某个矩形区域,这个区域的0改为1,1改为0,每次查询只查询某一个点的值是0还是1. 方法:二维线段树,这个东东我纠结了好久才慢慢弄好.二维线段树其实就就是在第一位区间的每个节点下再建一颗线段树,表示第二维的区间. 在修改的时候只需要先找到第一维的对应区间,在在这个区间的弟二维中查找对应区间,再做修改即可.而查找的时候,由于不同的第一维区间可能会有包含关系,所以需要对每个目标所在第一维区间查找第二维…
Get Many Persimmon Trees POJ - 2029 Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, th…
Mobile phones POJ - 1195 Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each s…
题目大意: 就是在二维的空间内进行单个的修改,或者进行整块矩形区域的最大最小值查询 二维线段树树,要注意的是第一维上不是叶子形成的第二维线段树和叶子形成的第二维线段树要  不同的处理方式,非叶子形成的线段树总是在自身的叶子处不能直接更新数据,而是要以一维下他的左右孩子对应的位置数据进行更新. #include <bits/stdc++.h> using namespace std; #define N 505 #define ls o<<1 #define rs o<<…
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #include <iostream> using namespace std; int N,M; double ma[110<<2][1010<<2]; void pushUpY(int xu,int u){ ma[xu][u]=max(ma[xu][u<<1], ma[…
Mosaic Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Submission(s): 213    Accepted Submission(s): 50 Problem Description The God of sheep decides to pixelate some pictures (i.e., change them into picture…
题意: 给一个矩阵,每次查询一个子矩阵内的最大最小值,然后更新子矩阵中心点为(Max+Min)/2. 解法: 由于是矩阵,且要求区间最大最小和更新单点,很容易想到二维的线段树,可是因为之前没写过二维的线段树,所以没跳出来.后来熟悉了一下,原来很多细节地方都没有考虑到. 这里build,update,query都分为两个函数,第一个为Y轴的(sub_update),第二个为X轴的(update),不仅每个sub_update或sub_build后面要加Y轴的pushup函数,而且每个update或…
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l),求出该区域内的最大值(A)和最小值(B),输出(A+B)/2,并用这个值更新矩阵[x,y]的值 思路:裸的二维线段树,用树套树实现 # include<cstdio> # include<cstring> # include<algorithm> using namesp…
题目链接: D. Vanya and Treasure time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Vanya is in the palace that can be represented as a grid n × m. Each room contains a single chest, an the room…
Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=95149#problem/G Description The God of sheep decides to pixelate some pictures (i.e., change them into pictures with mosaic). Here's how he is go…
P1716 - 上帝造题的七分钟 From Riatre    Normal (OI)总时限:50s    内存限制:128MB    代码长度限制:64KB 背景 Background 裸体就意味着身体. 描述 Description “第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵.第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的操作.第三分钟,k说,要能查询,于是便有了求给定矩形区域内的全部数字和的操作.第…
今天练习赛的题....又是线段树的变换..拿到题我就敲了个点更新区间查询的..果断超时...然后想到了可以将每个数与合表示成不进位的二进制数..这样就可以区间进行更新了..比赛的时候写搓了..刚重写了一遍过~~ 为了表示每位的二进制数...线段树开成二维的...第一维老样子~记是树中哪个点..第二维记当前段之和的不进位二进制数...因为最多到10^5...也就是不会超过2^20...第二维开个20就够了.... 区间更新如:   3 3    这段全xor 3...3+3的不进位二进制数为(2,…
题目链接 给一个n*n的方格, 每个方格有值. 每次询问, 给出三个数x, y, l, 求出以x, y为中心的边长为l的正方形内的最大值与最小值, 输出(maxx+minn)/2, 并将x, y这个格子的值改为(maxx+minn)/2.题目保证l为奇数. 二维线段树的单点更新, 区间查询. #include<bits/stdc++.h> using namespace std; #define pb(x) push_back(x) #define ll long long #define m…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1859 Matrix Searching Time Limit: 10 Seconds      Memory Limit: 32768 KB Given an n*n matrix A, whose entries Ai,j are integer numbers ( 1 <= i <= n, 1 <= j <= n ). An operation FIND t…
                                                                                       E. XOR on Segment You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on this array: Calculate the sum of cu…
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 54 Accepted Submission(s): 21   Problem Description 世界上上最远的距离不是相隔天涯海角而是我在你面前可你却不知道我爱你                ―― 张小娴 前段日子,枫冰叶子给Wiskey做了个征婚启事,聘…
分析: "如果你对树状数组比较熟悉,不难发现可怜求的是后缀和" 设数列为\(A\),那么可怜求的就是\(A_{l-1}\)到\(A_{r-1}\)的和(即\(l-1\)的后缀减\(r\)的后缀,\(\sum_{i=l-1}^{r-1}A_i\)),而答案为\(A_l\)到\(A_r\)的和(即\(\sum_{i=l}^{r}A_i\))这两种答案都包含\(A_l\)到\(A_{r-1}\)的和,因此只需判断\(A_{l-1}\)与\(A_r\)相等的概率就行了 那么怎么算? 考虑记下每…
Description 给定一个长度为n的正整数数列a[i]. 定义2个位置的f值为两者位置差与数值差的和,即f(x,y)=|x-y|+|a[x]-a[y]|. 你需要写一个程序支持2种操作(k都是正整数): Modify x k:将第x个数的值修改为k. Query x k:询问有几个i满足f(x,i)<=k.询问不仅要考虑当前数列,还要考虑任意历史版本,即统计任意位置上出现过的任意数值与当前的a[x]的f值<=k的对数.(某位置多次修改为同样的数值,按多次统计) Main 令F(x,y)=…
「ZJOI2017」树状数组(二维线段树) 吉老师的题目真是难想... 代码中求的是 \(\sum_{i=l-1}^{r-1}a_i\),而实际求的是 \(\sum_{i=l}^{r}a_i\),所以我们直接判断 \(a_{l-1}\) 和 \(a_r\) 是否相等就行了. 我们用二维线段树,一维存左端点 \(l\),一维存右端点 \(r\),里面存 \(a_l=a_r\) 的概率. 若 \(a\in [1,l-1],b\in [l,r]\),操作不在 \(b\),概率为 \(1-p\) 若 \…