每一项按顺序理解之后裸敲,每个代码最多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. WebStorm 在 Mac 版本的基本设置,包括 ES6、Node.js、字体大小等

    WebStorm 在 Mac 和 win 的设置有区别,便于以后用到快速查找,记之. 要设置先点击 WebStorm 字样如下图: 后点击 Preferences 字样如下图: 设置 es6 语法, ...

  2. ArrayList遍历的三种方法

    在输出很多的ArrayList的元素时,用普通的for循环太麻烦,因此本文介绍三种遍历ArrayList的方法 package test; public class Student { private ...

  3. msf生成后门拿shell

    0X01简介 这里我本来想学习 msf利用漏洞反弹shell的 但是 没有靶机....等找了靶机在弄吧 kali 172.18.5.118 靶机  172.18.5.240 先尝试能不能ping通 好 ...

  4. JDBC API访问数据库的基本步骤。

    JDBC本质:官方定义了一套操作所有关系型数据库的规则(接口),各个数据库厂商实现这个接口,提供数据库驱动jar包. 我们可以使用这套接口(JDBC)编程,真正执行的代码是驱动jar包中的实现类. 任 ...

  5. centos64位编译32位程序

    test.c #include <stdio.h> int main() { printf("sizeof long is %d\n",sizeof(long)); ; ...

  6. 【重点突破】—— UniApp 微信小程序开发官网学习Two

    一.使用Vue.js注意事项 Vue.js在uni-app中使用的差异: 新增:uni-app除了支持Vue实例的生命周期,还支持应用启动.页面显示等生命周期 受限:发布到H5时支持所有vue的语法, ...

  7. leetcode-mid-backtracking-17. Letter Combinations of a Phone Number

    mycode  68.26% class Solution(object): def letterCombinations(self, digits): """ :typ ...

  8. springBoot 动态注入bean(bean的注入时机)

    springBoot 动态注入bean(bean的注入时机) 参考博客:https://blog.csdn.net/xcy1193068639/article/details/81517456

  9. 洛谷P1190 接水问题

    题目名称:接水问题 题目来源 [洛谷P1190] (https://www.luogu.org/problemnew/show/P1190)​ 题目描述 学校里有一个水房,水房里一共有\(m\)个龙头 ...

  10. 记录一下WPF中自寄宿asp.net服务添加urlacl的问题

    asp.net公开服务地址时,由于当前用户权限问题,会导致服务地址未添加到urlacl池中报错. 关于添加urlacl的细节,请参考我之前的文章:asp.net self host and urlac ...