大工程 施工中...

各种各样的模版,一个代码解决

(施工中,尚未完工)

  1 #include<cstdio>
  2 #include<cstring>
  3 #include<algorithm>
  4 #include<queue>
  5 using namespace std;
  6 
  7 #define ll long long
  8 
  9 struct Math{
 10     inline ll Max(ll a,ll b){
 11         return a>b?a:b;
 12     }
 13     inline ll Min(ll a,ll b){
 14         return a<b?a:b;
 15     }
 16     inline void swap(ll &a,ll &b){
 17         a^=b^=a^=b;
 18     }
 19 }M;
 20 
 21 
 22 struct Edge{
 23     ll u,v,w;
 24 };
 25 
 26 struct Edges{
 27     #define maxm (100000)
 28     #define maxn (10000)
 29     ll u[maxm*2+5],v[maxm*2+5],w[maxm*2+5];
 30     ll first[maxn+5],next[maxm*2+5];
 31     ll tot=0;
 32     inline void addedge(ll a,ll b,ll c){
 33         tot++;u[tot]=a,v[tot]=b,w[tot]=c;
 34         next[tot]=first[a];
 35         first[a]=tot;
 36     }
 37 };
 38 
 39 struct SegTree{
 40     #define lc(x) (x<<1)
 41     #define rc(x) (x<<1|1)
 42     #define maxn (100000)
 43     ll sum[(maxn<<2)+5],tag[(maxn<<2)+5];
 44     inline void pushup(ll v){sum[v]=sum[lc(v)]+sum[rc(v)];}
 45     inline void pushdown(ll v,ll l,ll r){
 46         if(tag[v]){
 47             ll mid=l+r>>1;
 48             tag[lc(v)]+=tag[v];
 49             tag[rc(v)]+=tag[v];
 50             sum[lc(v)]+=tag[v]*(mid-l+1);
 51             sum[rc(v)]+=tag[v]*(r-mid);
 52             tag[v]=0;
 53         }
 54     }
 55     void update(ll v,ll l,ll r,ll left,ll right,ll add){
 56         if(l>=left&&r<=right){
 57             sum[v]+=add*(r-l+1);tag[v]+=add;
 58             return;
 59         }
 60         pushdown(v,l,r);
 61         ll mid=l+r>>1;
 62         if(left<=mid)update(lc(v),l,mid,left,right,add);
 63         if(mid<right)update(rc(v),mid+1,r,left,right,add);
 64         pushup(v);
 65     }
 66     ll query(ll v,ll l,ll r,ll left,ll right){
 67         if(l>=left&&r<=right)return sum[v];
 68         ll mid=l+r>>1,ans=0;
 69         pushdown(v,l,r);
 70         if(left<=mid)ans+=query(lc(v),l,mid,left,right);
 71         if(mid<right)ans+=query(rc(v),mid+1,r,left,right);
 72         return ans;
 73     }
 74 };
 75 
 76 struct Lca{
 77     #define maxn (100000)
 78     Edges e;
 79     ll n;
 80     ll dep[maxn+5],p[maxn+5][25];
 81     void dfs(ll x){
 82         for(ll i=e.first[x];i;i=e.next[i]){
 83             ll y=e.v[i];
 84             if(!dep[y]){
 85                 dep[y]=dep[x]+1,p[y][0]=x;
 86                 dfs(y);
 87             }
 88         }
 89     }
 90     void init(){
 91         for(ll i=1;i<=n;i++)if(!dep[i])dep[i]=1,dfs(i);
 92         for(ll j=1;j<=20;j++)for(ll i=1;i<=n;i++)p[i][j]=p[p[i][j-1]][j-1];
 93     }
 94     ll lca(ll a,ll b){
 95         if(dep[a]<dep[b])M.swap(a,b);
 96         for(ll i=20;i>=0;i--)
 97             if(dep[p[a][i]]>=dep[b])
 98                 a=p[a][i];
 99         if(a==b)return a;
100         for(ll i=20;i>=0;i--)
101             if(p[a][i]!=p[b][i])
102                 a=p[a][i],b=p[b][i];
103         return p[a][0];
104     }
105 };
106 
107 struct Tarjan{
108     
109 };
110 
111 struct Heap{
112     #define maxn (100000)
113     #define lc(x) (x<<1)
114     #define rc(x) (x<<1|1)
115     #define fa(x) (x>>1)
116     ll heap[maxn+5],size;
117     void pushup(ll x){
118         while(x>1){
119             if(heap[x]>=heap[fa(x)])M.swap(heap[x],heap[fa(x)]),x=fa(x);
120             else return;
121         }
122     }
123     void pushdown(ll x){
124         while(lc(x)<=size){
125             ll k=-1;
126             if(heap[x]<heap[lc(x)])k=lc(x);
127             if(rc(x)<=size&&heap[x]<heap[rc(x)])k=rc(x);
128             if(k==-1)return;
129             M.swap(heap[x],heap[k]),x=k;
130         }
131     }
132     inline ll top(){return heap[1];}
133     inline void pop(){heap[1]=heap[size--];pushdown(1);}
134     inline void push(ll x){heap[++size]=x;pushup(size);}
135 };
136 
137 struct DijkstraHeap{
138     #define maxn (100000)
139     struct point{
140         ll id,d;
141         bool operator <(const point &a)const{return d>a.d;}
142     };
143     Edges e;
144     priority_queue<point>q;
145     ll dis[maxn+5];
146     ll dijkstra(ll s,ll t){
147         memset(dis,0x3f,sizeof dis);
148         dis[s]=0;q.push((point){s,0});
149         while(!q.empty()){
150             point g=q.top();
151             ll x=g.id,d=g.d;
152             if(d!=dis[x])continue;
153             for(ll i=e.first[x];i;i=e.next[i]){
154                 ll y=e.v[i];
155                 if(dis[x]+e.w[i]<dis[y]){
156                     dis[y]=dis[x]+e.w[i];
157                     q.push((point){y,dis[y]});
158                 }
159             }
160         }
161         return dis[t];
162     }
163 };
164 
165 struct Floyd{
166 
167 };
168 
169 struct Kruskal{
170 
171 };
172 
173 struct Prim{
174 
175 };
176 
177 struct DisjointSet{
178 
179 };
180 
181 struct Kmp{
182 
183 };
184 
185 struct ST{
186     
187 };
188 
189 int main(){
190     return 0;
191 }
View Code

猜你喜欢

转载自www.cnblogs.com/Railgunforever/p/9925130.html