【树状数组】POJ 2155 Matrix】的更多相关文章

题目传送门 题意:n头牛,1~n的id给它们乱序编号,已知每头牛前面有多少头牛的编号是比它小的,求原来乱序的编号 分析:从后往前考虑,最后一头牛a[i] = 0,那么它的编号为第a[i] + 1编号:为1,倒数第二头牛的编号为除去最后一头牛的编号后的第a[i-1] + 1编号:为3,其他的类推,所以可以维护之前已经选掉的编号,求第k大的数字,sum[rt] 表示该区间已经被选掉的点的个数.另外树状数组也可以做,只不过用二分优化查找第k大的位置. 收获:逆向思维,求动态第K大 代码(线段树): /…
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers wa…
一道dfs序+树状数组的题 因为并没有get到dfs序以及对树状数组也不熟练卡了很久orz dfs序: in和out是时间戳 dfs序可以将树转化成为一个序列,满足区间 -> 子树 然后就可以用树状数组之类的维护序列的东东来维护了 ; void dfs(int u, int fa) { seq[++idx] = u; in[u] = idx; for(int i = head[u];i;i = nxt[i]) { int v = l[i]; if(v != fa) { dfs(v, u); }…
题目传送门 题意:两种操作,问u到v的距离,并且u走到了v:把第i条边距离改成w 分析:根据DFS访问顺序,将树处理成链状的,那么回边处理成负权值,那么LCA加上BIT能够知道u到v的距离,BIT存储每条边的信息,这样第二种操作也能用BIT快速解决 利用RMQ的写法不知哪里写挫了,改用倍增法 /************************************************ * Author :Running_Time * Created Time :2015/10/6 星期二…
题目传送门 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int cnt[MAX_N]; int ans[MAX_N]; ; struct node { int s, e; int id; }cow[MAX_N]; inline int read(void) { , f = ; char ch = getchar (); ; ch = getchar…
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32950   Accepted: 11943 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 col…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16797   Accepted: 6312 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…
[题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [代码] #include <cstring> #include <cstdio> const int N=1010; using namespace std; int c[N][N],n,m,T; char op[2]; void add(int x,int y){ int i,j,k…
Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 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…
附一篇经典翻译,学习 树状数组  http://www.hawstein.com/posts/binary-indexed-trees.html /** * @author johnsondu * @time 2015-8-22 * @type 2D Binary Index Tree * @strategy 如果翻转的是(x1,y1), (x2,y2)区域.则相当于 * 翻转(0, 0)~(x2, y2), 然后再翻转(0,0)~(x1-1, y2) * (0, 0)~(x2, y1-1),…