제출 #862863

#제출 시각아이디문제언어결과실행 시간메모리
862863sleepntsheep크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++17
100 / 100
288 ms165204 KiB
#include <cstdio> #include <cstring> #include <cassert> #include <string> #include <deque> #include <vector> #include <map> #include <queue> #include <algorithm> #include <iostream> #include <utility> using namespace std; using ll = long long; using ld = long double; #define ShinLena cin.tie(nullptr)->sync_with_stdio(false) #define N 1000005 #define M 40000005 #define ALL(x) x.begin(), x.end() char A[M]; int L[M], R[M], root[N], len[N], ALLOC = 1, cur = 0; int persist0(char c) { A[ALLOC] = c; return ALLOC++; } int persist1(int l, int r) { int p = ALLOC++; L[p] = l, R[p] = r; return p; } int build(int l, int r) { if (l == r) return persist0(0); return persist1(build(l, (l+r)/2), build((l+r)/2+1, r)); } int upd(int v, int l, int r, int p, char c) { if (l == r) return persist0(c); if (p <= (l+r)/2) return persist1(upd(L[v], l, (l+r)/2, p, c), R[v]); return persist1(L[v], upd(R[v], (l+r)/2+1, r, p, c)); } int qry(int v, int l, int r, int p) { if (l == r) return A[v]; if (p <= (l+r)/2) return qry(L[v], l, (l+r)/2, p); return qry(R[v], (l+r)/2+1, r, p); } void P() { #if 0 for (int i = 0; i < len[cur]; ++i) printf("%c", qry(root[cur], 0, 1000000, i)); puts(""); #endif } void Init() { root[0] = build(0, 1000000); P(); } void TypeLetter(char c) { ++cur; len[cur] = len[cur - 1] + 1; root[cur] = upd(root[cur-1], 0, 1000000, len[cur - 1], c); P(); } void UndoCommands(int u) { int f = cur++ - u; root[cur] = root[f]; len[cur] = len[f]; P(); } char GetLetter(int k) { P(); return qry(root[cur], 0, 1000000, k); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...