随笔分类 -  树状数组&&线段树

摘要:通过枚举每个点,也就是枚举可能的每个教练,得到在他之前的比他小的数的个数,比他大的数的个数,他之后的比他小的数的个数,比他大的数的数的个数,这个过程可通过树状数组等手段进行优化 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define LL long long 5 using namespace std; 6 const int maxn=20000+10; 7 const int maxm=100000; 8 int n,a[maxn],sm1[maxn],sm2[ma 阅读全文
posted @ 2013-05-21 14:59 LJ_COME!!!!! 阅读(152) 评论(0) 推荐(0)
摘要:树状数组,优化查询 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn=5000+10; 6 int n; 7 int a[maxn],c[maxn]; 8 int lowbit(int x) 9 {10 return x&(-x);11 }12 int query(int x)13 {14 int sum=0;15 while(x)16 {17 sum+=c[x];18 x-=... 阅读全文
posted @ 2013-05-20 19:20 LJ_COME!!!!! 阅读(126) 评论(0) 推荐(0)
摘要:复习了下线段树线段树的区间修改这道题有调试了两个多小时,怎么没进步啊,wa的原因是两个int形相乘,结果如果是long形,不仅结果的变量要用long,这两个数也得是long形,不然仍会溢出,原来就犯过同样的错误,怎么又犯了,还有找了那么长时间,k靠!!!!!!!!!!!!还有还有,如果要组成if else 语句,要有括号就都有,不能只有一个有#include <iostream> #include <cstdio> #include <algorithm> #define LL __int64 using namespace std; int n,tot; 阅读全文
posted @ 2013-03-09 18:59 LJ_COME!!!!! 阅读(178) 评论(0) 推荐(0)
摘要:dp水题,不解释#include <iostream> #include <cstdio> using namespace std; const int maxn=1000+10; int v[maxn]; long long sumv[maxn]; int main() { int n; while(~scanf("%d",&n)&&n) { int i,j; for(i=1;i<=n;i++) scanf("%d",&v[i]); memset(sumv,0,sizeof(sumv)); 阅读全文
posted @ 2013-02-02 16:28 LJ_COME!!!!! 阅读(113) 评论(0) 推荐(0)
摘要:此题不难,可以转化为求解区间内的个数和,树状数组比较便捷,结果大,用long long#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; const int maxn=1000; int road[maxn+10][maxn+10]; int temp[maxn+10]; int n,m,k; long long num=0; int sumx[maxn+10]; int lowbit(int x) 阅读全文
posted @ 2013-01-26 15:31 LJ_COME!!!!! 阅读(125) 评论(0) 推荐(0)
摘要:主要是dfs,只要dfs这一步想到,也就是怎样把问题转化为区间求和,就很容易用树状数组来求解#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn= 100000; int head[maxn+10],e[maxn+10],num[maxn+10],lim[maxn+10],sumx[maxn+10],vis[maxn+10]; int nextx[maxn+10]; int n,m,tot,tem; void dfs(int x 阅读全文
posted @ 2013-01-24 19:20 LJ_COME!!!!! 阅读(147) 评论(0) 推荐(0)
摘要:线段树区间修改入门题目。快被这个长整形给整死啦。以后如果对自己的算法的正确性有80%的把握,就去看一下细节,非常认真的看一遍,一行一行的看,这样其实更省时间,就比如我这次调来调去,调了4个多小时,最后才突然发现。//线.3段树区间修改 #include <iostream> #include <stdio.h> #include <cstring> using namespace std; const int maxn=100000; __int64 sum[maxn*3],d[maxn*3]; int v[maxn+10]; int n,q; int ql 阅读全文
posted @ 2013-01-08 16:25 LJ_COME!!!!! 阅读(129) 评论(0) 推荐(0)
摘要:线段树入门题#include <iostream> #include <stdio.h> #include <memory.h> using namespace std; const int maxn=50000; const int inf=1<<30; int n,q; int minv[maxn*3],maxv[maxn*3]; void init() { for(int i=0;i<maxn*3;i++) { minv[i]=inf; maxv[i]=-1; } } void update(int no,int p,int l,in 阅读全文
posted @ 2013-01-07 18:52 LJ_COME!!!!! 阅读(123) 评论(0) 推荐(0)
摘要:树状数组#include <iostream> #include <string.h> #include <stdio.h> using namespace std; const int maxn1=100000; const int maxn2=20010; int c[maxn1+10],v[maxn2],l[maxn2],r[maxn2]; int n; int lowbit(int x) { return x&(-x); } void add(int x) { while(x<=maxn1)//要细心 { c[x]+=1; x+=low 阅读全文
posted @ 2013-01-01 18:53 LJ_COME!!!!! 阅读(144) 评论(0) 推荐(0)