POJ 2481Cows(树状数组 + 好题)】的更多相关文章

预备知识 st表(Sparse Table) 主要用来解决区间最值问题(RMQ)以及维护区间的各种性质(比如维护一段区间的最大公约数). 树状数组 单点更新 数组前缀和的查询 拓展:原数组是差分数组时,可进行区间更新,单点查询,当然想区间查询也有办法(维护两个树状数组即可). 区别 树状数组用来维护一个具有区间可减(加)性质的工具,所以可以用来维护区间前缀和. 区间最值不具有区间可减性,所以不能使用树状数组进行维护,而使用st表. st表的思想 初始化 预处理数组, f[x][i] 表示区间[x…
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 128380    Accepted Submission(s): 53795 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任…
Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 70674   Accepted: 26538 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swappin…
開始用瓜神说的方法撸了一发线段树.早上没事闲的看了一下树状数组的方法,于是又写了一发树状数组 树状数组: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #includ…
第一次做树状数组,这个东西还是蛮神奇的,通过一个简单的C数组就可以表示出整个序列的值,并且可以用logN的复杂度进行改值与求和. 这道题目我根本不知道怎么和树状数组扯上的关系,刚开始我想直接按图来遍历来做,后来用树状数组做完都跑了600+MS,那样估计是TLE了. 做法就是用DFS把整个图重建一遍,代号小的点在叶子,代号大的点为根.记录每个根的起始点号为 idl,根点号为 idh,则求某个根的苹果和就直接调用树状数组的sum即可. 不过前提是要建好树,我一开始不明白为什么要建一颗标准树,即就是按…
(卧槽,居然规定了修改的两点直接相连,亏我想半天) 非常水的题,用dfs序(而且不用重复,应该是直接规模为n的dfs序)+树状数组可以轻松水 收获:树状数组一遍A(没啥好骄傲的,那么简单的东西) #include <cstdio> #include <iostream> using namespace std; ,n,m,p,q,a[],l[],pos[],end[],son[],bro[],h[]; void add(int x,int y) { while(x<=N) {…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27092   Accepted: 8033 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been…
Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42898   Accepted: 18664 Description 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 st…
这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms. #include<iostream> #include<algorithm> using namespace std; ]; int main() { int i,j,t,n; scanf("%d",&n); mat[]=; ;i<n;i++) { scanf("%d",&t); mat[i]=t+; ;j<i;j++) if(mat[j]&g…
http://poj.org/problem?id=2299 最初做离散化的时候没太确定可是写完发现对的---由于后缀数组学的时候,,这样的思维习惯了吧 1.初始化as[i]=i:对as数组依照num[]的大小间接排序 2.bs[as[i]]=i:如今bs数组就是num[]数组的离散化后的结果 3.注意,树状数组中lowbit(i)  i是不能够为0的,0&(-0)=0,死循环... #include <cstdio> #include <cstring> #include…