HDU 4911
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4911一场多校的签到题,树状数组离散化求逆序数#include #include #include #include using namespace std ;typedef __int64 ll ;int n,k...
         阅读全文
 
            
         
        
            
    HDU 4339 Query
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4339血与泪,伤与痛,无须多言线段树找数列中任意起点最多有多少连续的1View Code #include <iostream>#include <string.h>using namespace std ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=1000001 ;char s1[maxn],s2[maxn] ;int tree[maxn<<2] ;int n ;v
         阅读全文
 
            
         
        
            
    HDU 3333 Turing Tree
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3333离线算法,和上一题一模一样。。。View Code #include <iostream>#include <algorithm>#include <map>using namespace std ;const int maxn=30001 ;typedef __int64 LL ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1map <int,int> hash ;struct n
         阅读全文
 
            
         
        
            
    HDU 3874 Necklace
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3874今天和涂涂新学的离线算法,太牛了大概就是先接收所有数据,然后按查询右边界排序,从左往右更新,遇到之前加过的数就删掉,因为按右边界排序,所以查询区间不断右移,删掉不会出错View Code #include #...
         阅读全文
 
            
         
        
            
    HDU 4027 Can you answer these queries?
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4027线段树成段更新的题目,开方次数有限,一个区间都是1就lazy。仿hh风格的线段树,真漂亮啊View Code #include <iostream>#include <cmath>using namespace std ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=100002 ;typedef __int64 LL ;LL sum[maxn<<2] ;int l
         阅读全文
 
            
         
        
            
    HDU 1698 Just a Hook
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1698做的第一道线段树成段更新的题目,lazy标志起到的作用的延迟更新(为了保证O(logN)的效率,不延迟就变成O(N))。这道题反正就询问一次,最后直接输出即可。View Code #include <iostream>using namespace std ; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1const int maxn=100002 ;int sum[maxn<<2] ;int lazy[
         阅读全文
 
            
         
        
            
    HDU 2795 Billboard
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2795下午做的题,线段树单点更新广告牌高h宽w,尽可能在高处挂广告。注意h可能很大,但是我们注意到h比n大就没有意义了,这时我们让h=n(开始因为这个re了)View Code #include <iostream>using namespace std ;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=200002 ;int h,w,n ;int MAX[maxn<<2] ;void
         阅读全文
 
            
         
        
            
    HDU 1394 Minimum Inversion Number
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1394求最小逆序数,逆序数的树状数组求法昨天学会了,今天这题开始用个无脑O(n*n*log(n))的方法,果断超时。其实逆序数只用求一边,每移动一次数列,逆序数增加num[i]-1个,对应减少n-num[i]个,递推即可。View Code #include <stdio.h>#include <stdlib.h> #include <string.h>int n;int tree[5001],num[5001];int lowbit(int i){ return i&am
         阅读全文
 
            
         
        
            
    HDU  2689 Sort it
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2689树状数组求逆序数,原来一直没搞明白,今天看了一遍文章讲的很清楚,下面把有关内容粘过来:对于小数据,可以直接插入树状数组,对于大数据,则需要离散化,所谓离散化,就是将100 200 300 400 500 ---> 1 2 3 4 5这里主要利用树状数组解决计数问题。首先按顺序把序列a[i]每个数插入到树状数组中,插入的内容是1,表示放了一个数到树状数组中。然后使用sum操作获取当前比a[i]小的数,那么当前i - sum则表示当前比a[i]大的数,如此反复直到所有数都统计完,比如4 3 1 2 i
         阅读全文
 
            
         
        
            
    HDU 3792 Twin Prime Conjecture
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3792n为负数,静态查询,用树状数组写,蛋疼可见一斑。打素数表的时候内层循环对i再加一个判断,是为了防止i*j因为溢出而恒真(引用自sx老祖)View Code #include <iostream>using namespace std ;const int MAX=100001;int prime[MAX],tree[MAX],num[MAX];int lowbit(int i){ return i&(-i);} void update(int x,int val){ for(int 
         阅读全文
 
            
         
        
            
    HDU 3584 Cube
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3584裸三维树状数组。。。除了三维的容斥要稍微想一下别的都和一维、二维的一样了View Code #include <iostream>using namespace std;const int MAX=101;int n;int tree[MAX][MAX][MAX];int lowbit(int i){ return i&(-i);}void update(int x,int y,int z){ for(int i=x;i<=n;i+=lowbit(i)) for(int j=y
         阅读全文
 
            
         
        
            
    HDU 2642 Stars
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2642裸二维树状数组,没有秒杀,坑点是这题的询问是x1,x2,y1,y2(其实题目说得清清楚楚,惯性思维害死人?写完不过sample无力吐槽)。然后犯了一个巨2的笔误,死活没查出来,还是让路人王同学看出来的、、、、跪了View Code #include <iostream>using namespace std;const int MAX=1010;int vis[MAX][MAX],tree[MAX][MAX];int lowbit(int i){ return i&(-i);}voi
         阅读全文
 
            
         
        
            
    HDU 1892 See you~
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1892二维树状数组,很裸。。。View Code #include <iostream>#include <algorithm> #include <cstring>using namespace std;const int MAX=1010;int weight[MAX][MAX],tree[MAX][MAX];int lowbit(int i){ return i&(-i);}void update(int x,int y,int val){ for(int i
         阅读全文
 
            
         
        
            
    HDU 1541 Stars
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1541画星星,注意要把所有点向右平移一位,否则update会死循环(在(0,0))ps:数组一定要开够啊啊啊View Code #include <stdio.h>#include <string.h>const int maxn1=15001;const int maxn2=32001;int n;int tree[maxn2],ans[maxn1];int lowbit(int i){ return i&(-i);}void update(int i,int val){ w
         阅读全文
 
            
         
        
            
    HDU 1166 敌兵布阵(2)
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1166老题新做,树状数组,比线段树省了300k内存View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>const int maxn=51000;int s[maxn];int nCase=1,n;int lowbit(int i){return i&(-i);} void update(int i,int val){ while(i<=
         阅读全文
 
            
         
        
            
    HDU 4217 Data Structure?
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4217经典的线段树问题,找第k小数。注意sum用__int64View Code #include <stdio.h>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=300000;int tree[maxn<<2];int temp;void build(int l,int r,int rt){ tree[rt]=r-l+1; if(l==r) return; int m=(l+r)&
         阅读全文
 
            
         
        
            
    HDU 1166 敌兵布阵
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1166线段树,单点增减,区间求和View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>#define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int maxn=51000; int sum[maxn<<2]; int nCase=1; int pushup(i
         阅读全文
 
            
         
        
            
    HDU 1754 I Hate It
    
            
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1754线段树,单点更新,区间最值。学习自http://www.notonlysuccess.com/index.php/segment-tree-complete/View Code #include <stdio.h>#include <string.h> #include <stdlib.h>#include <math.h>#define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const
         阅读全文
 
            
         
    
 
    
 
 | 
                 
             
         |