模板

高精度

 

 

高斯消元

 

 

树状数组求逆序对

 

归并排序求逆序对

 

线段树

 

 

 

线段树合并

 

 

hash的插头DP

 

 

 

 

 

 

 

 

Tarjan相关

 

 

 

 

 

 

 

矩阵快速幂

 

Floyed

 

SPFA

Dijkstra

 

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int ans1[100100],ans2[100100];
 5 int main()
 6 {
 7     freopen("2.out","r",stdin);
 8     int n=5000;
 9     for(int i=1;i<=n;++i)  scanf("%d",&ans1[i]);
10     freopen("math2.out","r",stdin);
11     for(int i=1;i<=n;++i)  scanf("%d",&ans2[i]);
12     for(int i=1;i<=n;++i)
13         if(ans1[i]!=ans2[i])  {cout<<"Wrong Answer"<<endl;  return 0;}
14     cout<<"Accepted"<<endl;
15     return 0;
16 }
17 /*
18 g++ cmp.cpp -o cmp
19 ./cmp
20 */
cmp
  1 #include<bits/stdc++.h>
  2 #define maxn 100010
  3 #define inf 2000000000
  4 using namespace std;
  5 struct node{
  6     int son[2],fa,size/*子树的大小*/,val/*点的权值*/,tot/*当前树里权值是这么大的数的个数*/;
  7 }a[maxn];
  8 int n,x,opt;
  9 int root,cnt;
 10 int get(int x)//查询x是左儿子还是右儿子 0为左 1为右
 11 {
 12     return a[a[x].fa].son[1]==x;//son[1]==x return 1证明是1儿子也就是右儿子,如果写son[0]就完全反了
 13 }
 14 void update(int x)
 15 {
 16     a[x].size=a[a[x].son[0]].size+a[a[x].son[1]].size+a[x].tot;
 17 }
 18 void move(int x)//上旋
 19 {
 20     int fa=a[x].fa,grand_fa=a[fa].fa;
 21     int son1=get(x),son2=get(fa);
 22     a[fa].son[son1]=a[x].son[son1^1];  a[a[x].son[son1^1]].fa=fa;
 23     a[x].son[son1^1]=fa;  a[fa].fa=x;
 24     a[grand_fa].son[son2]=x;  a[x].fa=grand_fa;
 25     update(fa);  update(x);
 26 }
 27 void splay(int x,int Goal)//旋转到目标位置,儿子,父亲,爷爷在一条线上要双旋
 28 {
 29     while(a[x].fa!=Goal)
 30     {
 31         int fa=a[x].fa,grand_fa=a[fa].fa;
 32         int son1=get(x),son2=get(fa);
 33         if(grand_fa!=Goal)
 34         {
 35             if(son1==son2)  move(fa);
 36             else  move(x);
 37         }
 38         move(x);
 39     }
 40     if(!Goal)  root=x;
 41 }
 42 int find(int x)//找到权值为x的点在树上的位置
 43 {
 44     int now=root;
 45     while(a[now].val!=x&&a[now].son[a[now].val<x])  now=a[now].son[a[now].val<x];
 46     return now;
 47 }
 48 int pre(int x)
 49 {
 50     splay(find(x),0);
 51     int now=root;
 52     if(a[now].val<x)  return now;
 53     now=a[now].son[0];
 54     while(a[now].son[1])  now=a[now].son[1];
 55     return now;
 56 }
 57 int nex(int x)
 58 {
 59     splay(find(x),0);
 60     int now=root;
 61     if(a[now].val>x)  return now;
 62     now=a[now].son[1];
 63     while(a[now].son[0])  now=a[now].son[0];
 64     return now;
 65 }
 66 void insert(int x)
 67 {
 68     int now=root,fa=0;
 69     //a[now].val<x 返回1证明当前比查询点小,去右儿子里找
 70     while(a[now].val!=x&&now)  {fa=now;  now=a[now].son[a[now].val<x];}
 71     if(now)  {a[now].tot++;  update(now);}
 72     else
 73     {
 74         now=++cnt;
 75         if(fa)  a[fa].son[a[fa].val<x]=now;
 76         a[now].size=1;  a[now].tot=1;  a[now].fa=fa;  a[now].val=x;
 77     }
 78     splay(now,0);
 79 }
 80 void erase(int x)
 81 {
 82     int pos_pre=pre(x),pos_nex=nex(x);
 83     splay(pos_pre,0);  splay(pos_nex,pos_pre);
 84     int son=a[pos_nex].son[0];
 85     if(a[son].tot>1)  {a[son].tot--;  update(son);  splay(son,0);}
 86     else  a[pos_nex].son[0]=0;
 87 }
 88 int get_rank(int x)
 89 {
 90     splay(find(x),0);
 91     return a[a[root].son[0]].size;//本来size是所有比他小的数,加一才是他的排名,不加一的原因是比他小的数里有-inf
 92 }
 93 int get_num(int x)
 94 {
 95     int now=root;
 96     while(1)
 97     {
 98         int y=a[now].son[0];
 99         if(a[y].size>=x)  now=y;
100         else if(a[y].size+a[now].tot<x)
101         {
102             x-=a[y].size+a[now].tot;
103             now=a[now].son[1];
104         }
105         else return a[now].val;
106     }
107 }
108 int main()
109 {
110     insert(inf);  insert(-inf);  scanf("%d",&n);
111     while(n--)
112     {
113         scanf("%d%d",&opt,&x);
114         if(opt==1)  insert(x);
115         else if(opt==2)  erase(x);
116         else if(opt==3)  printf("%d
",get_rank(x));
117         else if(opt==4)  printf("%d
",get_num(x+1));//加1的原因是有inf在
118         else if(opt==5)  printf("%d
",a[pre(x)].val);
119         else  printf("%d
",a[nex(x)].val);
120     }
121     return 0;
122 }
平衡树
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int i;
 6     for(i=1;;i++)
 7     {
 8         printf("The result of No. %d Case is:  ",i);
 9         system("./1sj");  system("./1");  system("./1bl");
10         if (system("diff T.out W.out"))
11         {
12             printf("Wrong Answer
");
13             return 0;
14         }
15         else printf("Accepted
");
16     }
17     return 0;
18 }
19 /******************************
20 g++ 2sj.cpp -o 2sj
21 ./2sj
22 g++ 2bl.cpp -o 2bl
23 ./2bl
24 g++ 2.cpp -o 2
25 ./2
26 g++ pai.cpp -o pai
27 ./pai
28 ******************************/
29 /********************************************************
30 #!/bin/sh
31 dir=$GEDIT_CURRENT_DOCUMENT_DIR
32 name=$GEDIT_CURRENT_DOCUMENT_NAME
33 pre=${name%.*}
34 g++ $dir/$name -o $pre -g -Wall
35 if test $? -eq 0; then
36     gnome-terminal -x bash -c "time $dir/$pre;echo;read;"
37 fi
38 ********************************************************/
对拍
原文地址:https://www.cnblogs.com/hzjuruo/p/11855611.html