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

线段树

平衡树( Treap , sbt , spt )

#include <iostream>
#include <cstdio>
using namespace std ;
const int N = ;
struct node {
int lr , rr , r , v ;
node(){}
node( int lr , int rr , int r , int v ):lr(lr),rr(rr),r(r),v(v) {}
};
struct Treap {
node e[N];
int root , size ;
void init() {
size = ; root = - ;
}
void Rot_l( int &o ) {
int tmp = e[o].rr ;
e[o].rr = e[tmp].lr ;
e[tmp].lr = o ;
o = tmp ;
}
void Rot_r( int &o ) {
int tmp = e[o].lr ;
e[o].lr = e[tmp].rr ;
e[tmp].rr = o ;
o = tmp ;
}
void insert( int &o , int v , int r ) {
if( o == - ) {
o = size++ ;
e[o].lr = e[o].rr = - ;
e[o].r = r , e[o].v = v ;
} else if( v < e[o].v ) {
insert( e[o].lr , v , r ) ;
if( e[ e[o].lr ].r > e[o].r ) Rot_r(o) ;
} else {
insert( e[o].rr , v , r );
if( e[ e[o].rr ].r > e[o].r ) Rot_l(o) ;
}
}
void remove( int &o , int x ) {
if( e[o].v == x ) {
if( e[o].lr == - ) {
o = e[o].rr ;
} else if( e[o].rr == - ) {
o = e[o].lr ;
} else {
if( e[ e[o].lr ].r > e[ e[o].rr ].r ) {
Rot_r(o);
remove( e[o].rr , x );
} else {
Rot_l(o);
remove( e[o].lr , x ) ;
}
}
} else if( e[o].v > x ) {
remove( e[o].lr , x ) ;
} else {
remove( e[o].rr , x ) ;
}
}
int Find_max( int o ) {
if( o == - ) return - ;
while( e[o].rr != - ) o = e[o].rr ;
cout << e[o].r << endl ;
return e[o].v ;
}
int Find_min( int o ) {
if( o == - ) return - ;
while( e[o].lr != - ) o = e[o].lr ;
cout << e[o].r << endl ;
return e[o].v ;
}
} T ; int Run () {
int op , x , y ;
T.init() ;
while( cin >> op ) {
if( !op ) {
break ;
} else if( op == ) {
cin >> x >> y ;
T.insert( T.root , y , x ) ;
} else if( op == ) {
x = T.Find_max( T.root ) ;
if( x == - ) { cout << '' << endl ; continue ; }
T.remove( T.root , x ) ;
} else {
x = T.Find_min( T.root ) ;
if( x == - ) { cout << '' << endl ; continue ; }
T.remove( T.root , x ) ;
}
}
return ;
}
int main () {
ios::sync_with_stdio();
return Run() ;
}

Treap

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N = ;
const int M = ;
int mp[M];
struct node {
int lr , rr , siz , v ;
node(){}
node( int lr , int rr , int siz , int v ):lr(lr),rr(rr),siz(siz),v(v){}
};
struct SBT {
node e[N] ;
int rt , tot;
void init() { rt = tot = ; }
void Rot_l( int &o ) {
int y = e[o].rr ;
e[o].rr = e[y].lr;
e[y].lr = o ;
e[y].siz = e[o].siz ;
e[o].siz = e[ e[o].lr ].siz + e[ e[o].rr ].siz + ;
o = y ;
}
void Rot_r( int &o ) {
int y = e[o].lr ;
e[o].lr = e[y].rr ;
e[y].rr = o ;
e[y].siz = e[o].siz ;
e[o].siz = e[ e[o].lr ].siz + e[ e[o].rr ].siz + ;
o = y ;
}
void Maintain( int &o , bool flag ) {
if( !flag ) {
if( e[ e[ e[o].lr ].lr ].siz > e[ e[o].rr ].siz ) {
Rot_r(o) ;
} else if( e[ e[ e[o].lr ].rr ].siz > e[ e[o].rr ].siz ) {
Rot_l( e[o].lr ) ;
Rot_r(o);
} else return ;
} else {
if( e[ e[ e[o].rr ].rr ].siz > e[ e[o].lr ].siz ) {
Rot_l(o) ;
} else if( e[ e[ e[o].rr ].lr ].siz > e[ e[o].lr ].siz ) {
Rot_r( e[o].rr ) ;
Rot_l(o);
} else return ;
}
Maintain( e[o].lr , false ) ;
Maintain( e[o].rr , true ) ;
Maintain( o , false ) ;
Maintain( o , true ) ;
}
void Insert( int &o , int v ) {
if( !o ) {
o = tot++ ;
e[o] = node( , , , v ) ;
return ;
} else {
e[o].siz++ ;
if( v < e[o].v ) {
Insert( e[o].lr , v ) ;
} else {
Insert( e[o].rr , v ) ;
}
}
Maintain(o, v >= e[o].v ) ;
}
void Delete( int &o , int v ) {
if( !o ) return ;
e[o].siz-- ;
if( v < e[o].v ) Delete( e[o].lr , v ) ;
else if( v > e[o].v ) Delete( e[o].rr , v ) ;
else {
if( e[o].lr == ) o = e[o].rr ;
else if( e[o].rr == ) o = e[o].lr ;
else {
int y = e[o].rr ;
while( e[y].lr ) y = e[y].lr ;
e[o].v = e[y].v ;
Delete( e[o].rr , e[y].v ) ;
}
}
}
int Find_Max( int &o ) {
int y = o ;
while( e[y].rr ) y = e[y].rr ;
return e[y].v ;
}
int Find_Min( int &o ) {
int y = o ;
while( e[y].lr ) y = e[y].lr ;
return e[y].v ;
}
} T ;
int Run() {
int op , x , y ; T.init();
while( cin >> op ) {
if( op == ) break ;
else if( op == ) {
cin >> x >> y ;
mp[y] = x ;
T.Insert( T.rt , y ) ;
} else if( op == ) {
if( T.e[T.rt].siz == ) {
cout << '' << endl ;
} else {
int v = T.Find_Max( T.rt ) ;
cout << mp[v] << endl ;
T.Delete(T.rt,v);
}
} else {
if( T.e[T.rt].siz == ) {
cout << '' << endl ;
} else {
int v = T.Find_Min( T.rt );
cout << mp[v] << endl ;
T.Delete(T.rt,v);
}
}
}
return ;
}
int main()
{
#ifdef LOCAL
freopen("in","r",stdin);
#endif
ios::sync_with_stdio();
return Run();
}

Size Balance Tree

二叉堆

const int N =  ;
int h[N] , size ;
void Modify( int p ) {
if( p == ) return ;
if( h[p>>] > h[p] ) swap( h[p>>] , h[p] ) , Modify( p>> ) ;
} void Update( int p ) {
int l = p<< , r = p<<| , f = p ;
if( l <= size && h[l] < h[f] ) f = l ;
if( r <= size && h[r] < h[f] ) f = r ;
if( p != f ) swap( h[f] , h[p] ) , Update(f) ;
} void Pop() {
swap( h[] , h[size--] ) ; Update() ;
} void Push( int x ) {
h[++size] = x ; Modify( size ) ;
}

左偏树

最大优先 ~ 可合并堆

const int N =  ;
struct node {
int lr , rr , dis , fa , val ;
} T[N] ; inline int find( int k ) { return k == T[k].fa ? k : T[k].fa = find(T[k].fa) ; } int Merge( int a , int b ) {
if( !a ) return b ;
if( !b ) return a ;
if( T[a].val < T[b].val ) swap( a , b ) ;
T[a].rr = Merge( b , T[a].rr ) ;
T[ T[a].rr ].fa = a ;
if( T[ T[a].lr ].dis < T[ T[a].rr ].dis ) swap( T[a].lr , T[a].rr ) ;
if( T[a].rr == ) T[a].dis = ;
else T[a].dis = T[ T[a].rr ].dis + ;
return a ;
} int Pop( int a ) {
int l = T[a].lr , r = T[a].rr ;
T[l].fa = l , T[r].fa = r ;
T[a].lr = T[a].rr = T[a].dis = ;
return Merge( l , r ) ;
}

最短路( Dij , Spfa )

匈牙利

HK

带花树

Dinic

const int N = ;
const int M = ;
const int inf = 1e9 ; int s , t , n , m ;
int eh[N] , ef[M] , et[M] , ec[M] , nxt[M] , tot ;
int cur[N] , d[N] ;
bool vis[N] ; void init() {
memset( eh , - , sizeof eh ) ;
tot = ;
}
void addedge( int u , int v, int c , int f ) {
et[tot] = v , ec[tot] = c , ef[tot] = f , nxt[tot] = eh[u] , eh[u] = tot++ ;
et[tot] = u , ec[tot] = , ef[tot] = f , nxt[tot] = eh[v] , eh[v] = tot++ ;
} bool bfs() {
memset( vis , false , sizeof vis ) ;
queue<int>que;
que.push(s);
vis[s] = true ;
d[s] = ;
while( !que.empty() ) {
int u = que.front() ; que.pop() ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
int v = et[i] ;
if( !vis[v] && ef[i] < ec[i] ) {
vis[v] = true ;
d[v] = d[u] + ;
que.push(v);
}
}
}
return vis[t] ;
} int dfs( int x , int a ) {
if( x == t || a == ) return a ;
int flow = , F ;
for( int &i = cur[x] ; ~i ; i = nxt[i] ) {
int v = et[i] , c = ec[i] , &f = ef[i] ;
if( d[x] + == d[v] && ( F = dfs( v , min( a , c - f ) ) ) > ) {
f += F , ef[i^] -= F , a -= F , flow += F ;
if( a == ) break ;
}
}
return flow ;
} int MF() {
int flow = ;
while( bfs() ) {
memcpy( cur , eh , sizeof eh ) ;
flow += dfs( s , );
}
return flow ;
}

ISAP

const int N =  ;
const int M = ;
const int INF = 0x3f3f3f3f;
int n , m , s , t ;
int eh[N] , et[M] , nxt[M] , ef[M] , ec[M] , tot ; void init() {
memset( eh , - , sizeof eh ) ;
tot = ;
} void addedge( int u , int v , int c ) {
et[tot] = v ; ec[tot] = c ; ef[tot] = ; nxt[tot] = eh[u] ; eh[u] = tot++;
et[tot] = u ; ec[tot] = ; ef[tot] = ; nxt[tot] = eh[v] ; eh[v] = tot++;
} int d[N] , cur[N] , pre[N] , gap[N] ;
int Q[M] , S[M] ; void bfs() {
memset( d , - , sizeof d ) ;
memset( gap , , sizeof gap ) ;
int head = , tail = ;
d[t] = ; gap[]++ ;
Q[tail++] = t ;
while( head < tail ) {
int u = Q[head++] ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
int v = et[i] ;
if( d[v] != - ) continue ;
Q[tail++] = v ;
d[v] = d[u] + ;
gap[ d[v] ]++;
}
}
} int Sap( int n ) {
bfs();
memcpy( cur , eh , sizeof eh ) ;
int top = , u = s , flow = ;
while( d[s] < n ) {
if( u == t ) {
int Min = INF , inser ;
for( int i = ; i < top ; ++i ) {
if( Min > ec[ S[i] ] - ef[ S[i] ] ) {
Min = ec[ S[i] ] - ef[ S[i] ] ;
inser = i ;
}
}
for( int i = ; i < top ; ++i ) {
ef[ S[i] ] += Min ;
ef[ S[i]^ ] -= Min ;
}
flow += Min ;
top = inser ;
u = et[ S[top]^ ];
continue ;
}
bool flag = false ;
int v ;
for( int i = cur[u] ; ~i ; i = nxt[i] ) {
v = et[i] ;
if( ec[i] > ef[i] && d[v] + == d[u] ) {
flag = true ;
cur[u] = i ;
break ;
}
}
if( flag ) {
S[top++] = cur[u] ;
u = v ;
continue ;
}
int Min = n ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
if( ec[i] > ef[i] && d[ et[i] ] < Min ) {
Min = d[ et[i] ] ;
cur[u] = i ;
}
}
gap[ d[u] ]-- ;
if( !gap[ d[u] ] ) return flow ;
d[u] = Min + ;
gap[ d[u] ]++ ;
if( u != s ) u = et[ S[--top]^ ] ;
}
return flow ;
}

MCMF

const int N = ;
const int M = ;
const int INF = 0x3f3f3f3f; int eh[N] , ec[M] , et[M] , ef[M] , ew[M] , nxt[M] , tot ;
int pre[N] , dis[N] ;
bool vis[N] ;
int s , t , n , m , k ;
void init() {
memset( eh, - , sizeof eh );
tot = ;
}
void addedge( int u , int v , int cap , int cost ) {
et[tot] = v ; ef[tot] = ; ec[tot] = cap ; ew[tot] = cost ; nxt[tot] = eh[u] ; eh[u] = tot++ ;
et[tot] = u ; ef[tot] = ; ec[tot] = ; ew[tot] = -cost ; nxt[tot] = eh[v] ; eh[v] = tot++ ;
} bool spfa() {
memset( vis, false, sizeof vis ) ;
memset( dis ,0x3f , sizeof dis ) ;
memset( pre , - ,sizeof pre ) ;
queue<int>que;
dis[s] = ;
vis[s] = true ;
que.push(s) ;
while( !que.empty() ) {
int u = que.front() ; que.pop() ;
vis[u] =false ;
for( int i = eh[u] ; ~i ; i = nxt[i] ) {
int v = et[i] ;
if( ec[i] > ef[i] && dis[v] > dis[u] + ew[i] ) {
dis[v] = dis[u] + ew[i] ;
pre[v] = i ;
if( !vis[v] ) {
vis[v] = true ;
que.push(v) ;
}
}
}
}
return pre[t] != - ;
} int MCMF( int &cost ) {
int flow = ;
cost = ;
while( spfa() ) {
int Min = INF ;
for( int i = pre[t] ; ~i ; i = pre[ et[i^] ] ) {
if( Min > ec[i] - ef[i] ) {
Min = ec[i] - ef[i] ;
}
}
for( int i = pre[t] ; ~i ; i = pre[ et[i^] ] ) {
ef[i] += Min ;
ef[i^] -= Min ;
cost += ew[i] * Min ;
}
flow += Min ;
}
return flow ;
}

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. CF 149E Martian Strings 后缀自动机

    这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...

  2. React 项目使用 React-router-dom 4.0 以上版本时使用 HashRouter 怎么控制 history

    不添加 history 时,来回点击 Link 会在控制台报错如下 Warning: Hash history cannot PUSH the same path; a new entry will ...

  3. Linux安装配置redis 、启动redis、redis设置密码

    由于间隔时间较长.机器的环境不同等等原因,所以每次安装redis的时候总是不那么顺利,所以这次我要做个笔记 文章大部分内容源于https://blog.csdn.net/gisredevelopmen ...

  4. oracle11g安装补丁升级

    检查当前数据库CPU和PSU补丁信息 方法一: 登录数据库,检查DBA_REGISTRY_HIST视图. SYS@orcl> select *from dba_registry_history; ...

  5. 线下作业MySQL #20175201

    1.下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入world.sql,提交导入成功截图 2.编 ...

  6. js运行原理

    https://www.youtube.com/watch?v=8aGhZQkoFbQ

  7. Mysql 5.7安装与配置-默认密码

    Mysql下载 官方下载路径:https://dev.mysql.com/downloads/mysql/ 网盘下载(windows 32-64): 链接:https://pan.baidu.com/ ...

  8. vmware fusion 找不到可以连接的有效对等进程

    红框会有什么提示 vmware...,你点击允许

  9. mysql补0操作有什么意义?

    比如我们在创建int的时候会使用int(10)这样的方式来定义某一个列,但是这样定义是没有任何意义的. Create Table showzerofill(Val1 INT(5) ZEROFILL, ...

  10. leetcode-mid-dynamic programming-322. Coin Change - NO

    mycode 我开始错误的思路:先用大钱除总钱数来保证 fewest number of coins,当最后剩下的amount小于最小币值的货币时,就说明return -1,但是这样想是有问题的!!! ...