SCAU_WeiShenWahle 之省赛任务
每一项按顺序理解之后裸敲,每个代码最多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 之省赛任务的更多相关文章
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- SCNU 2015ACM新生赛决赛【F. Oyk闯机关】解题报告
题目大意:一个$N$$\times$$N$的阵列,每个格子有$X_{ij}$个调和之音,若每次只能选择走右边或下边,从左上角出发走到右下角,问最多能收集到多少个调和之音? ...
- SCNU 2015ACM新生赛初赛【1007. ZLM的扑克牌】解题报告
题目链接详见SCNU 2015新生网络赛 1007. ZLM的扑克牌 . 其实我在想这题的时候,还想过要不要设置求最小的排列,并且对于回文数字的话,可以把扑克牌折起来( ...
- SCNU 2015ACM新生赛初赛【1006. 3D打印】解题报告
题目链接详见SCNU 2015新生网络赛 1006. 3D打印 .出题思路来自codevs 3288. 积木大赛,属于模拟题. 首先我们把“选择从第L部分到第R部分”理 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- 第七届山东省ACM省赛
激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...
随机推荐
- Jenkins-ssh远程执行nohup- java无法退出
一,初步 #执行方式 ssh 192.168.2.103 " nohup java -jar /home/a/ipf/ight/feedback/ixxxedback-platform-1. ...
- 配置文件:mainfest.xml
AndroidManifest.xml 是每个android程序中必须的文件. 它位于整个项目的根目录,描述了package中暴露的组件(activities,services, 等等),他们各自 ...
- 【模板】【数论】二次剩余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 ...
- [模板][HDU]P2544[单源最短路][SPFA]
题目就不放了,主要是写一下SPFA,很少写,今天特别学了一个用STL的队列来做的. 代码: #include<iostream> #include<cstdio> #inclu ...
- css使用2
一.盒子模型 盒子模型 margin:用来调节盒子与盒子之间的距离(标签与标签之间距离) border:盒子的包装厚度(边框) padding:内部物体与盒子之间距离(文本与边框之间的距离) cont ...
- JAVA语言课堂测试源代码及使用截图
1源代码 第一部分 package 开学测试.java;class ScoreInformation {String stunumber;String name;double mathematicss ...
- 双重Iterator 报错!!!!
List list = new ArrayList(); list.add(new String[]{"0","s1","0038",&qu ...
- 转载:JIRA_7.13(破解)安装教程
参考:https://blog.csdn.net/weixin_38229356/article/details/84875205 参考2:https://www.codercto.com/a/399 ...
- 聊一聊几种常用web图片格式:gif、jpg、png、webp
前言 在大多数的web页面中,图片占到了页面大小的60%-70%.因此在web开发中,不同的场景使用合适的图片格式对web页面的性能和体验是很重要的.图片格式种类非常多,本文仅针对几种web应用中常用 ...
- kurento搭建以及运行kurento-hello-world
搭建环境的系统是ubuntu 1.kurento服务器搭建 运行如下脚本即可完成安装 #!/bin/bash echo "deb http://ubuntu.kurento.org trus ...