06 2012 档案
【总结】线段树
摘要:1、单点更新。【HDU】1166 敌兵布阵【HDU】1754 I Hate It【POJ】3264 Balanced Lineup【HDU】3074 Multiply game【POJ】2352 Stars【HDU】1394 Minimum Inversion Number【HDU】2795 Billboard【HDU】4046 Panda【POJ】2828 Buy Tickets【ZOJ】3279 Ants【FOJ】1962 新击鼓传花游戏【FOJ】1921 栀子花开【Codeforces】159C String Manipulation 1.0【POJ】2886 Who Gets the
阅读全文
【UVa】11992 Fast Matrix Operations
摘要:1 #include<cstdio> 2 #define INF 0x7FFFFFFF 3 #define MAXN 1000010 4 struct node 5 { 6 int cnt,son[4],kind[4]; 7 int big,small,sum,add,cover; 8 }; 9 node tree[MAXN<<2]; 10 int size,SUM,BIG,SMALL; 11 inline int MAX(int x,int y) 12 { 13 return x>y?x:y; 14 } 15 inline int MIN(int ...
阅读全文
【POJ】2155 Matrix
摘要:1 #include<cstdio> 2 #include<cstring> 3 #define MAXN 1010 4 int ans,n,tree[MAXN<<2][MAXN<<2]; 5 void SubBuild(int t,int L,int R,int rt) 6 { 7 tree[t][rt]=0; 8 if(L!=R) 9 { 10 int mid=(L+R)>>1; 11 SubBuild(t,L,mid,rt<<1); 12 SubBuild(t,mid+1,R,rt<<1|1); ...
阅读全文
【POJ】2019 Cornfields
摘要:1 #include<cstdio> 2 #define MAXN 300 3 struct node 4 { 5 int big[MAXN<<2],small[MAXN<<2]; 6 }; 7 node tree[MAXN<<2]; 8 int n,b; 9 inline int MAX(int x,int y) 10 { 11 return x>y?x:y; 12 } 13 inline int MIN(int x,int y) 14 { 15 return x>y?y:x; 16 } 17 void SubBuild(int t
阅读全文
【HDU】1823 Luck and Love
摘要:1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 #define MAXN 110 5 #define MAXM 1010 6 struct node 7 { 8 int big[MAXM<<2]; 9 }; 10 node tree[MAXN<<2]; 11 inline int MAX(int x,int y) 12 { 13 return x>y?x:y; 14 } 15 void SubBuild(int t,int L,int R,int rt) 1
阅读全文
【HDU】3333 Turing Tree
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 typedef __int64 LL; 6 #define MAXN 30010 7 #define MAXM 100010 8 int a[MAXN],b[MAXN],vis[MAXN]; 9 LL ans[MAXM],tree[MAXN<<2];10 struct node11 {12 int left,right,pos;13 friend bool operator&l
阅读全文
【HDU】3954 Level up
摘要:1 #include<cstdio> 2 #define MAXN 10010 3 #define MAXM 11 4 #define INF 2147483647 5 int n,k,need[MAXM]; 6 struct node 7 { 8 int big,lazy; 9 }; 10 node tree[MAXM][MAXN<<2]; 11 inline int MAX(int x,int y) 12 { 13 return x>y?x:y; 14 } 15 inline void PushUp(int t,int rt) 16 { 17 t...
阅读全文
【UVa】11983 Weird Advertisement
摘要:1 #include<cstdio> 2 #include<algorithm> 3 typedef long long LL; 4 #define MAXN 30010 5 using namespace std; 6 int n,k; 7 struct Seg 8 { 9 int left,right,high,flag; 10 friend bool operator<(Seg a,Seg b) 11 { 12 if(a.high==b.high) 13 return a.flag<b.flag; 14 ...
阅读全文
【HDU】2871 Memory Control
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 #define MAXN 50010 6 struct node 7 { 8 int left,right,sum,lazy,s,e,cnt,cover; 9 }; 10 node tree[MAXN<<2]; 11 inline void PushUp(int mid,int L,int R,int rt) 12 { 13 tree[rt].left=tree[rt<&
阅读全文
【FOJ】1608 Huge Mission
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 #define MAXN 50010 6 struct time 7 { 8 int s,t,ef; 9 friend bool operator<(time a,time b)10 {11 return a.ef>b.ef;12 }13 };14 struct node15 {16 int sum,lazy;17 };18 time p[MAXN*10];19 no...
阅读全文
【FOJ】2022 车站
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define MAXN 500010 5 using namespace std; 6 int x[MAXN]; 7 bool vis[MAXN]; 8 struct cmd 9 { 10 char s[6]; 11 int val; 12 }; 13 struct node 14 { 15 int left,right,val; 16 }; 17 node tree[MAXN<<2]; 18 cmd p[MAXN];
阅读全文
【FOJ】1921 栀子花开
摘要:1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 #define MAXN 10010 5 int tree[MAXN<<2],ca=1; 6 inline void PushUp(int rt) 7 { 8 tree[rt]=min(tree[rt<<1],tree[rt<<1|1]); 9 }10 void Build(int L,int R,int rt)11 {12 if(L==R)13 scanf("%d",&tre
阅读全文
【POJ】1436 Horizontally Visible Segments
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #include<algorithm> 5 #include<set> 6 using namespace std; 7 #define MAXN 16010 8 #define INF 123456789 9 struct Seg 10 { 11 int y1,y2,x; 12 friend bool operator<(Seg a,Seg b) 13 { 14 return a.x<b.x; 15 }
阅读全文
【POJ】2886 Who Gets the Most Candies?
摘要:1 #include<cstdio> 2 #define MAXN 500010 3 int n,k,ans,cnt; 4 int prime[]={2,3,5,7,11,13,17}; 5 struct node 6 { 7 char name[12]; 8 int val; 9 }; 10 node p[MAXN]; 11 int tree[MAXN<<2]; 12 void AntiPrime(int res,int count,int index,int limit) 13 { 14 if(res<=n) 15 { 16 ...
阅读全文
【HDU】3255 Farming
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 typedef __int64 LL; 5 #define MAXN 30010 6 using namespace std; 7 struct Plant 8 { 9 int x1,y1,x2,y2,s; 10 }; 11 struct Seg 12 { 13 int left,right,high,flag; 14 friend bool operator<(Seg a,Seg b) 15 { 16 ...
阅读全文
【HDU】3642 Get The Treasury
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 typedef __int64 LL; 5 using namespace std; 6 #define MAXN 1010 7 struct Point 8 { 9 int x,y,z; 10 void Input() 11 { 12 scanf("%d%d%d",&x,&y,&z); 13 } 14 }; 15 struct Rectangle 16 { 17 Point a,b; 18
阅读全文
【POJ】2482 Stars in Your Window
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define MAXN 20010 5 typedef __int64 LL; 6 using namespace std; 7 struct Seg 8 { 9 LL left,right,val,high;10 friend bool operator<(Seg a,Seg b)11 {12 if(a.high!=b.high)13 return a.high<b.high;14 r...
阅读全文
【HDU】1255 覆盖的面积
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cmath> 5 #include<algorithm> 6 #define MAXN 5010 7 #define EPS 1e-8 8 using namespace std; 9 struct Line 10 { 11 double left,right,high; 12 int flag; 13 }; 14 struct node 15 { 16 int cover; 17 double
阅读全文
【FOJ】1962 新击鼓传花游戏
摘要:1 #include<cstdio> 2 #define MAXN 500010 3 int tree[MAXN<<2]; 4 inline void PushUp(int rt) 5 { 6 tree[rt]=tree[rt<<1]+tree[rt<<1|1]; 7 } 8 void Build(int L,int R,int rt) 9 {10 if(L==R)11 tree[rt]=1;12 else13 {14 int mid=(L+R)>>1;15 Build(L,mid,rt<<1);16 ...
阅读全文
【HDU】1828 Picture
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #define MAXN 20010 6 #define INF 123456789 7 using namespace std; 8 struct Line 9 {10 int left,right,high,flag;11 };12 Line p[MAXN];13 struct node14 {15 int sum,cnt,left,right,vertical;16 }tree
阅读全文
【HDU】1199 Color the Ball
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define MAXN 2010 5 using namespace std; 6 struct Line 7 { 8 int left,right,color; 9 }; 10 Line p[MAXN]; 11 int x[MAXN<<2],tree[MAXN<<4]; 12 bool vis[MAXN<<2]; 13 inline void PushDown(int rt) 14 { 15 i
阅读全文
【POJ】1389 Area of Simple Polygons
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #define MAXN 100010 5 struct Line 6 { 7 int left,right,high,flag; 8 }; 9 struct node 10 { 11 int sum,cover; 12 }; 13 Line p[MAXN]; 14 node tree[MAXN<<2]; 15 int x[MAXN]; 16 inline bool Out(int x1,int y1,int x2,int y
阅读全文
【HDU】4027 Can you answer these queries?
摘要:1 #include<cstdio> 2 #include<cmath> 3 typedef __int64 LL; 4 #define EPS 1e-9 5 #define MAXN 100010 6 struct node 7 { 8 LL sum; 9 int flag;10 };11 node tree[MAXN<<2];12 inline void PushUp(int rt)13 {14 tree[rt].flag=tree[rt<<1].flag&tree[rt<<1|1].flag;15 tree[rt].su
阅读全文