STL必背
bool cmpx(re a,re b){return a.x<b.x;}
重载运算符
1.快速幂
while(cnt){ if(cnt&1)ans=ans*b; cnt=cnt>>1; b=b*b; }
2.矩阵快速幂(yuohua)
3.lca
#include<bits/stdc++.h> using namespace std; const int N=1e5+999; int fa[N][24]; vector<int> v[N]; int n; void ad(int x,int y){ v[x].push_back(y); v[y].push_back(x); } int dep[N],siz[N],zson[N][24]; void dfs(int fath,int x){ dep[x]=dep[fath]+1; fa[x][0]=fath; siz[x]=1; zson[x][0]=-1; int maxer=0; for(int i=0;i<v[x].size();i++){ int dot=v[x][i]; if(dot!=fath){ dfs(x,dot); siz[x]+=siz[dot]; if(maxer<siz[dot]){maxer=siz[dot];zson[x][0]=dot;} } } } int lca(int x,int y){ if(x==y)return x; if(dep[x]<dep[y])swap(x,y); // X for(int i=20;i>=0;i--) if(dep[x]-(1<<i)>=dep[y])x=fa[x][i]; if(x==y)return x; if(dep[y]==1)return y; for(int i=20;i>=0;i--) if(fa[x][i]!=fa[y][i]){x=fa[x][i];y=fa[y][i];} return fa[x][0]; } int q,root; int main(){ ios::sync_with_stdio(0); freopen("p.in","r",stdin); freopen("p.out","w",stdout); cin>>n>>q>>root; for(int i=1;i<=n-1;i++){ int a,b; cin>>a>>b; ad(a,b); } dfs(0,root); for(int i=1;i<=20;i++) for(int j=1;j<=n;j++) fa[j][i]=fa[fa[j][i-1]][i-1]; for(int i=1;i<=q;i++){ int a,b; cin>>a>>b; cout<<lca(a,b)<<endl; } return 0; }
5.system("diff -b -B 1.out 2.out")
6.SET
set<int> s[N]; set<int>::iterator it,it2,it3;
s.begin()
s.end()
s.insert().first