POJ2887 Big String 块状链表
2014-07-25 19:34
239 查看
块状链表初体验 ╮(╯▽╰)╭~~
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define mxn 1000020 #define N 1000 #define N2 2003 char s[mxn]; struct node { char a[N2]; int cnt; node() { cnt = 0; nxt = pre = NULL; } node *nxt, *pre; void split() { if( cnt < N2 - 3 ) return ; node* tmp = new node; for( int i = cnt / 2 + 1; i <= cnt; ++i ) tmp -> a[++tmp->cnt] = a[i]; cnt /= 2; tmp -> pre = this; tmp -> nxt = nxt; nxt = tmp; } void insert( int k, char c ) { if( k > cnt ) { if( nxt == NULL ) { a[++cnt] = c; split(); } else { nxt -> insert( k - cnt, c ); } return ; } for( int i = cnt + 1; i > k + 1; --i ) a[i] = a[i-1]; a[k+1] = c; cnt++; split(); } char get_k( int k ) { if( k > cnt ) return nxt -> get_k( k - cnt ); return a[k]; } }*head; int main() { // freopen( "tt.txt", "r", stdin ); while( scanf( "%s", s + 1 ) != EOF ) { head = new node; node* now = head; int tot = 0; for( int i = 1; s[i]; ++i ) { now -> a[++now->cnt] = s[i]; if( i > tot + N ) { now -> nxt = new node; now -> nxt -> pre = now; now = now -> nxt; tot += N; } } int m; scanf( "%d", &m ); while( m-- ) { char str[3]; scanf( "%s", str ); if( str[0] == 'Q' ) { int k; scanf( "%d", &k ); printf( "%c\n", head -> get_k( k ) ); continue; } int k; scanf( "%s %d", str, &k ); k--; head -> insert( k, str[0] ); } } return 0; }
相关文章推荐
- poj2887 Big String(块状链表)
- 【POJ2887】【块状链表】Big String
- 【POJ2887】【块状链表】Big String
- poj 2887 Big String(块状链表)
- [POJ 2887] Big String [块状链表]
- POJ 2887 Big String(块状链表)
- POJ 2887 Big String(块状链表)
- POJ2887(块状链表)
- poj2882 Big String(数据结构 - 块状链表)
- POJ2887 Big String(块状数组)
- POJ2887【块状链表】
- Big String-POJ2887块状数组
- poj 2887 Big String 块状链表
- Big String-POJ2887块状数组
- 块状链表 poj2887
- 块状链表基本操作及相关例题
- uva12538 Version Controlled IDE(可持续化Treap * 模板, STL ext/rope(块状链表))
- LOJ.6282.数列分块入门6(块状链表/分块)
- 数据结构与算法之:块状链表(或者叫块状数组)
- 块状链表模板