随笔分类 - 数据结构——线段树+树状数组
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1706trick:关于正数和负数的整除问题,正数整除是自动向下取整的,但负数是向上取整的即13/3=4.3 ->4 但-13/3=-4.3 ->-4#include #include #include #include #include #include #include #define maxn 32500#define maxe 11000#define INF 0x3f3f3f#define lson l,mid,u mid) Update(...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define maxn 105000 10 #define lson l,mid,u>1; 21 seg[u>1; 28 seg[u>1; 43 build(lson); 44 build(rson); 45 } 46 void Update(int...
阅读全文
摘要:题目链接:http://poj.org/problem?id=3468WA 在了数据类型上,seg[]要用longlong,输入也要注意. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define maxn 12500010 #define lson l,mid,u>1;22 seg[u>1;37 build(lson);38 build(rson);39 PushUp(u);40 }41 void Update(int...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define maxn 13005010 #define lson l,mid,u mid) Update(L,R,num,rson);51 Push_UP(u);52 }53 54 int main()55 {56 if(freopen("input.txt","r",stdin...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define maxn 22222210 #define lson l,mid,u>1; 28 build(lson);29 build(rson);30 Push_UP(u);31 }32 void Update(int loc,int num,int l,int r,int u){33 ...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define maxn 23005010 #define lson l,mid,u mid) ret =max(ret,Query(L,R,rson));49 return ret;50 }51 int main()52 {53 if(freopen("input.txt","r",stdi
阅读全文
摘要:分析看这个大神的,我的还是参考他说的算法实现的:http://www.dxmtb.com/blog/diff/ 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 const int maxm = 1000005; 7 const int maxn = 50005; 8 9 10 int C[maxn],next[maxn],B[maxn];11 int flag[maxm];12 st
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166;树状数组: 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 const int maxn = 50050; 8 int n,T; 9 int a[maxn];10 int C[maxn];11 int lowbit(int x){12 return x&(-x);13
阅读全文