每一项按顺序理解之后裸敲,每个代码最多15分钟,用模板题来测,超过15分钟算未理解

线段树

平衡树( Treap , sbt , spt )

  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std ;
  4. const int N = ;
  5. struct node {
  6. int lr , rr , r , v ;
  7. node(){}
  8. node( int lr , int rr , int r , int v ):lr(lr),rr(rr),r(r),v(v) {}
  9. };
  10. struct Treap {
  11. node e[N];
  12. int root , size ;
  13. void init() {
  14. size = ; root = - ;
  15. }
  16. void Rot_l( int &o ) {
  17. int tmp = e[o].rr ;
  18. e[o].rr = e[tmp].lr ;
  19. e[tmp].lr = o ;
  20. o = tmp ;
  21. }
  22. void Rot_r( int &o ) {
  23. int tmp = e[o].lr ;
  24. e[o].lr = e[tmp].rr ;
  25. e[tmp].rr = o ;
  26. o = tmp ;
  27. }
  28. void insert( int &o , int v , int r ) {
  29. if( o == - ) {
  30. o = size++ ;
  31. e[o].lr = e[o].rr = - ;
  32. e[o].r = r , e[o].v = v ;
  33. } else if( v < e[o].v ) {
  34. insert( e[o].lr , v , r ) ;
  35. if( e[ e[o].lr ].r > e[o].r ) Rot_r(o) ;
  36. } else {
  37. insert( e[o].rr , v , r );
  38. if( e[ e[o].rr ].r > e[o].r ) Rot_l(o) ;
  39. }
  40. }
  41. void remove( int &o , int x ) {
  42. if( e[o].v == x ) {
  43. if( e[o].lr == - ) {
  44. o = e[o].rr ;
  45. } else if( e[o].rr == - ) {
  46. o = e[o].lr ;
  47. } else {
  48. if( e[ e[o].lr ].r > e[ e[o].rr ].r ) {
  49. Rot_r(o);
  50. remove( e[o].rr , x );
  51. } else {
  52. Rot_l(o);
  53. remove( e[o].lr , x ) ;
  54. }
  55. }
  56. } else if( e[o].v > x ) {
  57. remove( e[o].lr , x ) ;
  58. } else {
  59. remove( e[o].rr , x ) ;
  60. }
  61. }
  62. int Find_max( int o ) {
  63. if( o == - ) return - ;
  64. while( e[o].rr != - ) o = e[o].rr ;
  65. cout << e[o].r << endl ;
  66. return e[o].v ;
  67. }
  68. int Find_min( int o ) {
  69. if( o == - ) return - ;
  70. while( e[o].lr != - ) o = e[o].lr ;
  71. cout << e[o].r << endl ;
  72. return e[o].v ;
  73. }
  74. } T ;
  75.  
  76. int Run () {
  77. int op , x , y ;
  78. T.init() ;
  79. while( cin >> op ) {
  80. if( !op ) {
  81. break ;
  82. } else if( op == ) {
  83. cin >> x >> y ;
  84. T.insert( T.root , y , x ) ;
  85. } else if( op == ) {
  86. x = T.Find_max( T.root ) ;
  87. if( x == - ) { cout << '' << endl ; continue ; }
  88. T.remove( T.root , x ) ;
  89. } else {
  90. x = T.Find_min( T.root ) ;
  91. if( x == - ) { cout << '' << endl ; continue ; }
  92. T.remove( T.root , x ) ;
  93. }
  94. }
  95. return ;
  96. }
  97. int main () {
  98. ios::sync_with_stdio();
  99. return Run() ;
  100. }

Treap

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. using namespace std;
  5. const int N = ;
  6. const int M = ;
  7. int mp[M];
  8. struct node {
  9. int lr , rr , siz , v ;
  10. node(){}
  11. node( int lr , int rr , int siz , int v ):lr(lr),rr(rr),siz(siz),v(v){}
  12. };
  13. struct SBT {
  14. node e[N] ;
  15. int rt , tot;
  16. void init() { rt = tot = ; }
  17. void Rot_l( int &o ) {
  18. int y = e[o].rr ;
  19. e[o].rr = e[y].lr;
  20. e[y].lr = o ;
  21. e[y].siz = e[o].siz ;
  22. e[o].siz = e[ e[o].lr ].siz + e[ e[o].rr ].siz + ;
  23. o = y ;
  24. }
  25. void Rot_r( int &o ) {
  26. int y = e[o].lr ;
  27. e[o].lr = e[y].rr ;
  28. e[y].rr = o ;
  29. e[y].siz = e[o].siz ;
  30. e[o].siz = e[ e[o].lr ].siz + e[ e[o].rr ].siz + ;
  31. o = y ;
  32. }
  33. void Maintain( int &o , bool flag ) {
  34. if( !flag ) {
  35. if( e[ e[ e[o].lr ].lr ].siz > e[ e[o].rr ].siz ) {
  36. Rot_r(o) ;
  37. } else if( e[ e[ e[o].lr ].rr ].siz > e[ e[o].rr ].siz ) {
  38. Rot_l( e[o].lr ) ;
  39. Rot_r(o);
  40. } else return ;
  41. } else {
  42. if( e[ e[ e[o].rr ].rr ].siz > e[ e[o].lr ].siz ) {
  43. Rot_l(o) ;
  44. } else if( e[ e[ e[o].rr ].lr ].siz > e[ e[o].lr ].siz ) {
  45. Rot_r( e[o].rr ) ;
  46. Rot_l(o);
  47. } else return ;
  48. }
  49. Maintain( e[o].lr , false ) ;
  50. Maintain( e[o].rr , true ) ;
  51. Maintain( o , false ) ;
  52. Maintain( o , true ) ;
  53. }
  54. void Insert( int &o , int v ) {
  55. if( !o ) {
  56. o = tot++ ;
  57. e[o] = node( , , , v ) ;
  58. return ;
  59. } else {
  60. e[o].siz++ ;
  61. if( v < e[o].v ) {
  62. Insert( e[o].lr , v ) ;
  63. } else {
  64. Insert( e[o].rr , v ) ;
  65. }
  66. }
  67. Maintain(o, v >= e[o].v ) ;
  68. }
  69. void Delete( int &o , int v ) {
  70. if( !o ) return ;
  71. e[o].siz-- ;
  72. if( v < e[o].v ) Delete( e[o].lr , v ) ;
  73. else if( v > e[o].v ) Delete( e[o].rr , v ) ;
  74. else {
  75. if( e[o].lr == ) o = e[o].rr ;
  76. else if( e[o].rr == ) o = e[o].lr ;
  77. else {
  78. int y = e[o].rr ;
  79. while( e[y].lr ) y = e[y].lr ;
  80. e[o].v = e[y].v ;
  81. Delete( e[o].rr , e[y].v ) ;
  82. }
  83. }
  84. }
  85. int Find_Max( int &o ) {
  86. int y = o ;
  87. while( e[y].rr ) y = e[y].rr ;
  88. return e[y].v ;
  89. }
  90. int Find_Min( int &o ) {
  91. int y = o ;
  92. while( e[y].lr ) y = e[y].lr ;
  93. return e[y].v ;
  94. }
  95. } T ;
  96. int Run() {
  97. int op , x , y ; T.init();
  98. while( cin >> op ) {
  99. if( op == ) break ;
  100. else if( op == ) {
  101. cin >> x >> y ;
  102. mp[y] = x ;
  103. T.Insert( T.rt , y ) ;
  104. } else if( op == ) {
  105. if( T.e[T.rt].siz == ) {
  106. cout << '' << endl ;
  107. } else {
  108. int v = T.Find_Max( T.rt ) ;
  109. cout << mp[v] << endl ;
  110. T.Delete(T.rt,v);
  111. }
  112. } else {
  113. if( T.e[T.rt].siz == ) {
  114. cout << '' << endl ;
  115. } else {
  116. int v = T.Find_Min( T.rt );
  117. cout << mp[v] << endl ;
  118. T.Delete(T.rt,v);
  119. }
  120. }
  121. }
  122. return ;
  123. }
  124. int main()
  125. {
  126. #ifdef LOCAL
  127. freopen("in","r",stdin);
  128. #endif
  129. ios::sync_with_stdio();
  130. return Run();
  131. }

Size Balance Tree

二叉堆

  1. const int N = ;
  2. int h[N] , size ;
  3. void Modify( int p ) {
  4. if( p == ) return ;
  5. if( h[p>>] > h[p] ) swap( h[p>>] , h[p] ) , Modify( p>> ) ;
  6. }
  7.  
  8. void Update( int p ) {
  9. int l = p<< , r = p<<| , f = p ;
  10. if( l <= size && h[l] < h[f] ) f = l ;
  11. if( r <= size && h[r] < h[f] ) f = r ;
  12. if( p != f ) swap( h[f] , h[p] ) , Update(f) ;
  13. }
  14.  
  15. void Pop() {
  16. swap( h[] , h[size--] ) ; Update() ;
  17. }
  18.  
  19. void Push( int x ) {
  20. h[++size] = x ; Modify( size ) ;
  21. }

左偏树

最大优先 ~ 可合并堆

  1. const int N = ;
  2. struct node {
  3. int lr , rr , dis , fa , val ;
  4. } T[N] ;
  5.  
  6. inline int find( int k ) { return k == T[k].fa ? k : T[k].fa = find(T[k].fa) ; }
  7.  
  8. int Merge( int a , int b ) {
  9. if( !a ) return b ;
  10. if( !b ) return a ;
  11. if( T[a].val < T[b].val ) swap( a , b ) ;
  12. T[a].rr = Merge( b , T[a].rr ) ;
  13. T[ T[a].rr ].fa = a ;
  14. if( T[ T[a].lr ].dis < T[ T[a].rr ].dis ) swap( T[a].lr , T[a].rr ) ;
  15. if( T[a].rr == ) T[a].dis = ;
  16. else T[a].dis = T[ T[a].rr ].dis + ;
  17. return a ;
  18. }
  19.  
  20. int Pop( int a ) {
  21. int l = T[a].lr , r = T[a].rr ;
  22. T[l].fa = l , T[r].fa = r ;
  23. T[a].lr = T[a].rr = T[a].dis = ;
  24. return Merge( l , r ) ;
  25. }

最短路( Dij , Spfa )

匈牙利

HK

带花树

Dinic

  1. const int N = ;
  2. const int M = ;
  3. const int inf = 1e9 ;
  4.  
  5. int s , t , n , m ;
  6. int eh[N] , ef[M] , et[M] , ec[M] , nxt[M] , tot ;
  7. int cur[N] , d[N] ;
  8. bool vis[N] ;
  9.  
  10. void init() {
  11. memset( eh , - , sizeof eh ) ;
  12. tot = ;
  13. }
  14. void addedge( int u , int v, int c , int f ) {
  15. et[tot] = v , ec[tot] = c , ef[tot] = f , nxt[tot] = eh[u] , eh[u] = tot++ ;
  16. et[tot] = u , ec[tot] = , ef[tot] = f , nxt[tot] = eh[v] , eh[v] = tot++ ;
  17. }
  18.  
  19. bool bfs() {
  20. memset( vis , false , sizeof vis ) ;
  21. queue<int>que;
  22. que.push(s);
  23. vis[s] = true ;
  24. d[s] = ;
  25. while( !que.empty() ) {
  26. int u = que.front() ; que.pop() ;
  27. for( int i = eh[u] ; ~i ; i = nxt[i] ) {
  28. int v = et[i] ;
  29. if( !vis[v] && ef[i] < ec[i] ) {
  30. vis[v] = true ;
  31. d[v] = d[u] + ;
  32. que.push(v);
  33. }
  34. }
  35. }
  36. return vis[t] ;
  37. }
  38.  
  39. int dfs( int x , int a ) {
  40. if( x == t || a == ) return a ;
  41. int flow = , F ;
  42. for( int &i = cur[x] ; ~i ; i = nxt[i] ) {
  43. int v = et[i] , c = ec[i] , &f = ef[i] ;
  44. if( d[x] + == d[v] && ( F = dfs( v , min( a , c - f ) ) ) > ) {
  45. f += F , ef[i^] -= F , a -= F , flow += F ;
  46. if( a == ) break ;
  47. }
  48. }
  49. return flow ;
  50. }
  51.  
  52. int MF() {
  53. int flow = ;
  54. while( bfs() ) {
  55. memcpy( cur , eh , sizeof eh ) ;
  56. flow += dfs( s , );
  57. }
  58. return flow ;
  59. }

ISAP

  1. const int N = ;
  2. const int M = ;
  3. const int INF = 0x3f3f3f3f;
  4. int n , m , s , t ;
  5. int eh[N] , et[M] , nxt[M] , ef[M] , ec[M] , tot ;
  6.  
  7. void init() {
  8. memset( eh , - , sizeof eh ) ;
  9. tot = ;
  10. }
  11.  
  12. void addedge( int u , int v , int c ) {
  13. et[tot] = v ; ec[tot] = c ; ef[tot] = ; nxt[tot] = eh[u] ; eh[u] = tot++;
  14. et[tot] = u ; ec[tot] = ; ef[tot] = ; nxt[tot] = eh[v] ; eh[v] = tot++;
  15. }
  16.  
  17. int d[N] , cur[N] , pre[N] , gap[N] ;
  18. int Q[M] , S[M] ;
  19.  
  20. void bfs() {
  21. memset( d , - , sizeof d ) ;
  22. memset( gap , , sizeof gap ) ;
  23. int head = , tail = ;
  24. d[t] = ; gap[]++ ;
  25. Q[tail++] = t ;
  26. while( head < tail ) {
  27. int u = Q[head++] ;
  28. for( int i = eh[u] ; ~i ; i = nxt[i] ) {
  29. int v = et[i] ;
  30. if( d[v] != - ) continue ;
  31. Q[tail++] = v ;
  32. d[v] = d[u] + ;
  33. gap[ d[v] ]++;
  34. }
  35. }
  36. }
  37.  
  38. int Sap( int n ) {
  39. bfs();
  40. memcpy( cur , eh , sizeof eh ) ;
  41. int top = , u = s , flow = ;
  42. while( d[s] < n ) {
  43. if( u == t ) {
  44. int Min = INF , inser ;
  45. for( int i = ; i < top ; ++i ) {
  46. if( Min > ec[ S[i] ] - ef[ S[i] ] ) {
  47. Min = ec[ S[i] ] - ef[ S[i] ] ;
  48. inser = i ;
  49. }
  50. }
  51. for( int i = ; i < top ; ++i ) {
  52. ef[ S[i] ] += Min ;
  53. ef[ S[i]^ ] -= Min ;
  54. }
  55. flow += Min ;
  56. top = inser ;
  57. u = et[ S[top]^ ];
  58. continue ;
  59. }
  60. bool flag = false ;
  61. int v ;
  62. for( int i = cur[u] ; ~i ; i = nxt[i] ) {
  63. v = et[i] ;
  64. if( ec[i] > ef[i] && d[v] + == d[u] ) {
  65. flag = true ;
  66. cur[u] = i ;
  67. break ;
  68. }
  69. }
  70. if( flag ) {
  71. S[top++] = cur[u] ;
  72. u = v ;
  73. continue ;
  74. }
  75. int Min = n ;
  76. for( int i = eh[u] ; ~i ; i = nxt[i] ) {
  77. if( ec[i] > ef[i] && d[ et[i] ] < Min ) {
  78. Min = d[ et[i] ] ;
  79. cur[u] = i ;
  80. }
  81. }
  82. gap[ d[u] ]-- ;
  83. if( !gap[ d[u] ] ) return flow ;
  84. d[u] = Min + ;
  85. gap[ d[u] ]++ ;
  86. if( u != s ) u = et[ S[--top]^ ] ;
  87. }
  88. return flow ;
  89. }

MCMF

  1. const int N = ;
  2. const int M = ;
  3. const int INF = 0x3f3f3f3f;
  4.  
  5. int eh[N] , ec[M] , et[M] , ef[M] , ew[M] , nxt[M] , tot ;
  6. int pre[N] , dis[N] ;
  7. bool vis[N] ;
  8. int s , t , n , m , k ;
  9. void init() {
  10. memset( eh, - , sizeof eh );
  11. tot = ;
  12. }
  13. void addedge( int u , int v , int cap , int cost ) {
  14. et[tot] = v ; ef[tot] = ; ec[tot] = cap ; ew[tot] = cost ; nxt[tot] = eh[u] ; eh[u] = tot++ ;
  15. et[tot] = u ; ef[tot] = ; ec[tot] = ; ew[tot] = -cost ; nxt[tot] = eh[v] ; eh[v] = tot++ ;
  16. }
  17.  
  18. bool spfa() {
  19. memset( vis, false, sizeof vis ) ;
  20. memset( dis ,0x3f , sizeof dis ) ;
  21. memset( pre , - ,sizeof pre ) ;
  22. queue<int>que;
  23. dis[s] = ;
  24. vis[s] = true ;
  25. que.push(s) ;
  26. while( !que.empty() ) {
  27. int u = que.front() ; que.pop() ;
  28. vis[u] =false ;
  29. for( int i = eh[u] ; ~i ; i = nxt[i] ) {
  30. int v = et[i] ;
  31. if( ec[i] > ef[i] && dis[v] > dis[u] + ew[i] ) {
  32. dis[v] = dis[u] + ew[i] ;
  33. pre[v] = i ;
  34. if( !vis[v] ) {
  35. vis[v] = true ;
  36. que.push(v) ;
  37. }
  38. }
  39. }
  40. }
  41. return pre[t] != - ;
  42. }
  43.  
  44. int MCMF( int &cost ) {
  45. int flow = ;
  46. cost = ;
  47. while( spfa() ) {
  48. int Min = INF ;
  49. for( int i = pre[t] ; ~i ; i = pre[ et[i^] ] ) {
  50. if( Min > ec[i] - ef[i] ) {
  51. Min = ec[i] - ef[i] ;
  52. }
  53. }
  54. for( int i = pre[t] ; ~i ; i = pre[ et[i^] ] ) {
  55. ef[i] += Min ;
  56. ef[i^] -= Min ;
  57. cost += ew[i] * Min ;
  58. }
  59. flow += Min ;
  60. }
  61. return flow ;
  62. }

BCC

SCC

KMP

Manancher

AC自动机

后缀数组

后缀自动机

DXL(精确覆盖,模糊覆盖)

SCAU_WeiShenWahle 之省赛任务的更多相关文章

  1. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  2. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. SCNU 2015ACM新生赛决赛【F. Oyk闯机关】解题报告

            题目大意:一个$N$$\times$$N$的阵列,每个格子有$X_{ij}$个调和之音,若每次只能选择走右边或下边,从左上角出发走到右下角,问最多能收集到多少个调和之音?       ...

  5. SCNU 2015ACM新生赛初赛【1007. ZLM的扑克牌】解题报告

            题目链接详见SCNU 2015新生网络赛 1007. ZLM的扑克牌 .         其实我在想这题的时候,还想过要不要设置求最小的排列,并且对于回文数字的话,可以把扑克牌折起来( ...

  6. SCNU 2015ACM新生赛初赛【1006. 3D打印】解题报告

            题目链接详见SCNU 2015新生网络赛 1006. 3D打印 .出题思路来自codevs 3288. 积木大赛,属于模拟题.         首先我们把“选择从第L部分到第R部分”理 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  9. 第七届山东省ACM省赛

    激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...

随机推荐

  1. Jenkins-ssh远程执行nohup- java无法退出

    一,初步 #执行方式 ssh 192.168.2.103 " nohup java -jar /home/a/ipf/ight/feedback/ixxxedback-platform-1. ...

  2. 配置文件:mainfest.xml

    AndroidManifest.xml 是每个android程序中必须的文件.   它位于整个项目的根目录,描述了package中暴露的组件(activities,services, 等等),他们各自 ...

  3. 【模板】【数论】二次剩余Cipolla算法,离散对数BSGS 算法

    Cipolla LL ksm(LL k,LL n) { LL s=1; for(;n;n>>=1,k=k*k%mo) if(n&1) s=s*k%mo; return s; } n ...

  4. [模板][HDU]P2544[单源最短路][SPFA]

    题目就不放了,主要是写一下SPFA,很少写,今天特别学了一个用STL的队列来做的. 代码: #include<iostream> #include<cstdio> #inclu ...

  5. css使用2

    一.盒子模型 盒子模型 margin:用来调节盒子与盒子之间的距离(标签与标签之间距离) border:盒子的包装厚度(边框) padding:内部物体与盒子之间距离(文本与边框之间的距离) cont ...

  6. JAVA语言课堂测试源代码及使用截图

    1源代码 第一部分 package 开学测试.java;class ScoreInformation {String stunumber;String name;double mathematicss ...

  7. 双重Iterator 报错!!!!

    List list = new ArrayList(); list.add(new String[]{"0","s1","0038",&qu ...

  8. 转载:JIRA_7.13(破解)安装教程

    参考:https://blog.csdn.net/weixin_38229356/article/details/84875205 参考2:https://www.codercto.com/a/399 ...

  9. 聊一聊几种常用web图片格式:gif、jpg、png、webp

    前言 在大多数的web页面中,图片占到了页面大小的60%-70%.因此在web开发中,不同的场景使用合适的图片格式对web页面的性能和体验是很重要的.图片格式种类非常多,本文仅针对几种web应用中常用 ...

  10. kurento搭建以及运行kurento-hello-world

    搭建环境的系统是ubuntu 1.kurento服务器搭建 运行如下脚本即可完成安装 #!/bin/bash echo "deb http://ubuntu.kurento.org trus ...