线段树&&树状数组
文章平均质量分 78
NOTTME
这个作者很懒,什么都没留下…
展开
-
Sicily9564
用线段树做还是超时,百度了一下发现有简便算法。 #include #include #include #include #include #include using namespace std; int xmin[1000005]={0}; int xmax[1000005]={0}; int ymin[1000005]={0}; int ymax原创 2013-12-03 20:50:03 · 523 阅读 · 0 评论 -
POJ3468(线段树+lazy思想)
#include <iostream> #include <cstdio> using namespace std; __int64 total=0; __int64 A[100000]; struct CNode { int left,right; CNode *leftchild,*rightchild; __int64 sum; __int64 inc; }; CNode* build(int l,int r) { CNode* root=new CNode; root->left原创 2013-07-16 10:59:06 · 602 阅读 · 0 评论 -
POJ2777(线段树)
color为-1时表示这一段的区间内有不同的颜色,需要继续遍历其左子树和右子树。 #include #include #include #include using namespace std; struct Node { int left; int right; Node *leftchild; Node *rightchild; int color; }; N原创 2013-07-04 15:45:42 · 546 阅读 · 0 评论 -
POJ2352(线段树)
不知道为什么一直TLE,用了线段树的数据结构应该不会超时才对。 #include #include #include #include using namespace std; struct Tree { int left,right; Tree *leftchild,*rightchild; int sum; }; Tree* build(int l,int r) { Tr原创 2013-07-10 09:43:17 · 528 阅读 · 0 评论 -
POJ2352(树状数组)
#include using namespace std; int c[32001]={0}; int lowbit(int x) { return x&(-x); } int getsum(int x) { int total=0; while (x>0) { total+=c[x]; x-=lowbit(x); } return total; } void upd原创 2013-07-09 21:07:59 · 503 阅读 · 0 评论 -
POJ1151(求矩阵的并面积) 离散化
#include #include #include #include using namespace std; struct rec { double x1; double y1; double x2; double y2; }; int find(double aim,double* arr,int T) { int i; for (i=0;i<=T-1;i++) {原创 2013-07-03 12:08:06 · 771 阅读 · 0 评论 -
POJ2299(树状数组)
求逆序数对。 看了一下别人的题解,发现这题还可以用树状数组的方法来做。 因为数据大小范围为0~999,999,999,若用此数作为数组下标肯定会超出内存限制,所以采用离散化的方法先将数据范围缩小。 比如9,1,4,3,5可以变为5,1,3,2,4来处理,这样数组最大的下标就是5,大大缩小了数据范围,因为n 思路是从头到尾循环一次,假设循环变量为pos,即当前位置为pos,则对C[i]求原创 2013-05-13 19:05:47 · 656 阅读 · 0 评论