二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include<string.h> #define N 1100 int c[N][N],visit[N][N],n; int number(int x) { return x&-x; } void insert(int x,int y,int z) { int i,j; for(i=x;i<=N;…
描述 Now I am leaving hust acm. In the past two and half years, I learned so many knowledge about Algorithm and Programming, and I met so many good friends. I want to say sorry to Mr, Yin, I must leave now ~~>.<~~. I am very sorry, we could not advanc…
You are given an N × N matrix. At the beginning every element is 0. Write a program supporting 2 operations: 1. Add x y value: Add value to the element Axy. (Subscripts starts from 0 2. Sum x1 y1 x2 y2: Return the sum of every element Axy for x1 ≤ x…
Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 785    Accepted Submission(s): 335 Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make the p…
http://acm.hdu.edu.cn/showproblem.php?pid=2642 题目大意:一个星空,二维的.上面有1000*1000的格点,每个格点上有星星在闪烁.一开始时星星全部暗淡着,有Q个操作: B x y 点亮一盏星星 D x y 熄灭一盏星星 Q fx tx fy ty 查询这个矩形里面亮着的星星的个数. 题解:首先,注意输入的x,y可能是(0,0),这样一来,用树状数组就不好维护了,所以将之平移一个单位,每当读入一对坐标,要进行x++,y++.. 其次,输入的查询,矩形…
试题链接:https://www.nowcoder.com/acm/contest/77/E 题目描述 情人节到了,小芳和小明手牵手,打算过一个完美的情人节,但是小刚偏偏也来了,当了一个明晃晃的电灯泡,小明很尴尬,就和小刚说,我交给你个任务,你完成了我俩就带你玩,否则你就回家吧.小刚很有当单身狗的觉悟,他坚决不想让小明过好情人节,同为单身狗的你能帮帮他吗?现在有一个n×n(1 <= n <= 1000)的格子,每一个格子都有一个电灯泡,可能是亮的,也可能是灭的(1代表亮, 0代表灭),现在有两…
忘记了单点更新时要在树状数组中减去原值..wa了一发 /* 矩形求和,单点更改 */ #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define maxn 1030 int bit[maxn][maxn],n; void add(int x,int y,int num){ for(int i=x;i<=n;i…
#include<cstdio> #include<cstring> using namespace std; typedef long long ll; ; ; ll c[N][N]; ]; int lowbit(int x) { return x&-x; } void add(int x,int y,int d) { for(int i=x;i<=N;i+=lowbit(i)) for(int j=y;j<=N;j+=lowbit(j)) c[i][j]=(…
碰到这种题一定要注意坐标是不是有序的,也要注意坐标是不是有0的,有的话需要+1处理 #include<bits/stdc++.h> using namespace std; #define maxn 1005 int bit[maxn][maxn],flag[maxn][maxn]; ]; void add(int x,int y,int num){ ;i+=i&-i) ;j+=j&-j) bit[i][j]+=num; } int query(int x,int y){ ;…
开心.jpg J.farm 先解释一下题意,题意就是一个n*m的矩形区域,每个点代表一个植物,然后不同的植物对应不同的适合的肥料k,如果植物被撒上不适合的肥料就会死掉.然后题目将每个点适合的肥料种类(不同的数字代表不同的种类)给出(最多n*m种肥料),然后T次操作,每次操作都是把以(x1,y1)为左上角,以(x2,y2)为右下角确定的矩形区域撒上种类为k的肥料,问T次操作后,死掉了多少植物. 这个题可以是个经典的二维树状数组的题目,通过二维树状数组维护区间,以及各种神奇操作过了这道题. 这道题有…