1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| #include<algorithm> #include<bitset> #include<cmath> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<deque> #include<iostream> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<utility> #include<vector> #include<numeric> #include<functional> #include<climits> #include<iomanip> using namespace std; #define rep(i,from,to) for(int i=(int)(from);i<=(int)(to);++i) #define rev(i,from,to) for(int i=(int)(from);i>=(int)(to);--i) #define For(i,to) for(int i=0;i<(int)(to);++i) #define see(x) (cerr<<(#x)<<'='<<(x)<<endl) #define printCase(i) printf("Case %d: ", i) #define endl '\n' #define coutP(i) cout<<fixed<<setprecision(i)
#define mmst(a,x) memset(a, x, sizeof(a)) typedef long long ll; typedef long double ld; typedef double db; inline ll read(){ ll x=0;bool s=1;char c=getchar(); while(c>'9'c<'0'){if(c=='-')s=0;c=getchar();} while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();} return s?x:~x+1; } void readch(char& ch) { do ch = getchar(); while (!isalpha(ch)); }
const int N = 1e6; const int SQN = 1e3; struct LinkedNodes { struct Node { Node* nxt; int size; char d[SQN * 2 + 10];
Node() { nxt = NULL; size = 0; }
void split() { if (size < SQN * 2) return ; Node* q = new Node; rep(i, SQN + 1, size) { q->append(d[i]); } q->nxt = nxt; nxt = q; size = SQN; }
void append(char c) { d[++size] = c; split(); }
void insert(char c, int x) { size++; rev(i, size, x + 1) { swap(d[i - 1], d[i]); } d[x] = c; split(); }
void output() { rep(i, 1, size) cout << d[i]; cout << endl; } };
Node* head; Node* tail; int size;
LinkedNodes() { head = new Node; tail = head; size = 0; }
char query(int x) { for (Node* p = head; p != NULL; p = p->nxt) { if (x <= p->size) return p->d[x]; else x -= p->size; } }
void append(char c) { while (tail->nxt != NULL) tail = tail->nxt; tail->append(c); size++; }
void insert(char c, int x) { for (Node* p = head; p != NULL; p = p->nxt) { if (x <= p->size) { p->insert(c, x); size++; break; } else { x -= p->size; } } }
void output() { for (Node* p = head; p != NULL; p = p->nxt) { p->output(); } } };
char s[N + 100]; int main() { LinkedNodes* lns = new LinkedNodes(); scanf("%s", s); int len = strlen(s); For(i, len) { lns->append(s[i]); } int m = read(); while (m--) { char o; readch(o); if (o == 'I') { char c; int x; readch(c); x = read(); if (x > lns->size) lns->append(c); else lns->insert(c, x); } else { int x = read(); printf("%c\n", lns->query(x)); } } return 0; }
|