voidreadch(char& ch){ // 读入字符 do ch = getchar(); while (!isalpha(ch)); }
voidcheck(node* p){ // 判断,记得要分裂 if (p->size >= (sqn << 1)) { node* q = new node; for (int i = sqn; i < p->size; i++) q->pb(p->d[i]); p->size = sqn, q->nxt = p->nxt, p->nxt = q; } }
voidinsert(char c, int pos){ // 元素插入,借助链表来理解 node* p = head; int tot, cnt; if (pos > llen++) { while (p->nxt != NULL) p = p->nxt; p->pb(c), check(p); return; } for (tot = head->size; p != NULL && tot < pos; p = p->nxt, tot += p->size); tot -= p->size, cnt = pos - tot - 1; for (int i = p->size - 1; i >= cnt; i--) p->d[i + 1] = p->d[i]; p->d[cnt] = c, p->size++; check(p); }
charquery(int pos){ // 查询 node* p; int tot; for (p = head, tot = head->size; p != NULL && tot < pos; p = p->nxt, tot += p->size); tot -= p->size; return p->d[pos - tot - 1]; }
intmain(){ scanf("%s %d", inits, &q), llen = strlen(inits); node* p = new node; head = p; for (int i = 0; i < llen; i++) { if (i % sqn == 0 && i) p->nxt = new node, p = p->nxt; p->pb(inits[i]); } char a; int k; while (q--) { readch(a); if (a == 'Q') scanf("%d", &k), printf("%c\n", query(k)); else readch(a), scanf("%d", &k), insert(a, k); } return0; }