省选前的任务计划
作者:互联网
因为太菜了,NOIP2020考挂了
要靠省选翻盘
可是现在压力大的一批
都没什么动力
就写一点计划 来监督自己
1.WC2021
2.string、ds尽可能熟练掌握
SAM+线段树合并
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int out = 0; bool flag = false; register char cc = getchar(); while (cc < '0' || cc > '9') { if (cc == '-') flag = true; cc = getchar(); } while (cc >= '0' && cc <= '9') { out = (out << 3) + (out << 1) + (cc ^ 48); cc = getchar(); } return flag ? -out : out; } inline void write(ll x, char ch) { if (x < 0) putchar('-'), x = -x; if (x == 0) putchar('0'); else { int num = 0; char cc[22]; while (x) cc[++num] = x % 10 + 48, x /= 10; while (num) putchar(cc[num--]); } putchar(ch); } const int L = 5e5 + 10, N = 1e6 + 10; int rt[N], ls[N * 40], rs[N * 40], sum[N * 40], tot, Left, Right; void add(int &u, int l, int r, int pos) { if (!u) u = ++tot; if (l == r) sum[u]++; else { int mid = (l + r) >> 1; if (pos <= mid) add(ls[u], l, mid, pos); else add(rs[u], mid + 1, r, pos); sum[u] = sum[ls[u]] + sum[rs[u]]; } } void merge(int &u, int x, int y) { if (!x || !y) u = (x | y); else { u = ++tot; merge(ls[u], ls[x], ls[y]), merge(rs[u], rs[x], rs[y]); sum[u] = sum[ls[u]] + sum[rs[u]]; } } int find(int u, int l, int r) { if (!u || !sum[u]) return -1; if (l == r) return l; int mid = (l + r) >> 1, pos = -1; if (mid < Right) pos = find(rs[u], mid + 1, r); if (pos == -1 && Left <= mid) pos = find(ls[u], l, mid); return pos; } int n, m, tax[L], ord[N], ed[L]; char s[L], t[L]; ll ans; struct sam { int trans[N][26], fa[N], len[N], las, nodeid; void init() { for (int c = 0; c < 26; c++) trans[0][c] = 1; for (int u = 1; u <= nodeid; u++) for (int c = 0; c < 26; c++) trans[u][c] = 0; las = nodeid = 1; } void ins(int c) { int p = las, np = ++nodeid; len[np] = len[p] + 1; for ( ; p && !trans[p][c]; p = fa[p]) trans[p][c] = np; if (!p) fa[np] = 1; else { int q = trans[p][c]; if (len[q] == len[p] + 1) fa[np] = q; else { int nq = ++nodeid; len[nq] = len[p] + 1; for (int i = 0; i < 26; i++) trans[nq][i] = trans[q][i]; fa[nq] = fa[q], fa[q] = fa[np] = nq; for ( ; p && trans[p][c] == q; p = fa[p]) trans[p][c] = nq; } } las = np; } void build() { for (int i = 1; i <= nodeid; i++) tax[len[i]]++; for (int i = 1; i <= n; i++) tax[i] += tax[i - 1]; for (int i = 1; i <= nodeid; i++) ord[tax[len[i]]--] = i; for (int i = nodeid; i; i--) { int now = ord[i]; if (now != 1) merge(rt[fa[now]], rt[fa[now]], rt[now]); } } } ss, st; int main() { scanf("%s", s + 1), n = strlen(s + 1); ss.init(); for (int i = 1; i <= n; i++) ss.ins(s[i] - 'a'), ed[i] = ss.las; for (int i = 1; i <= n; i++) add(rt[ed[i]], 1, n, i); ss.build(); for (int T = read(); T; T--) { scanf("%s", t + 1), m = strlen(t + 1); Left = read(), Right = read(), ans = 0; st.init(); int now = 1, l = 0; for (int i = 1; i <= m; i++) { int c = t[i] - 'a'; st.ins(c); while (now && !ss.trans[now][c]) now = ss.fa[now], l = ss.len[now]; now = ss.trans[now][c], l += (now != 1); //cout << now << " " << l << " ----------------------------- \n"; int pos = -1; while (now > 1) { pos = find(rt[now], 1, n); //cout << pos << " \n"; if (pos == -1 || pos - ss.len[ss.fa[now]] < Left) now = ss.fa[now], l = ss.len[now]; else break; } //cout << pos << "," << now << "," << l << " ===================\n"; int mat = (pos == -1 ? 0 : min(l, pos - Left + 1)); ans += max(0, st.len[st.las] - max(mat, st.len[st.fa[st.las]])); } write(ans, '\n'); } return 0; }View Code
splay+hash(自然溢出)
#include <bits/stdc++.h> #define check(x) (tr[fa[x]][1] == x) using namespace std; inline int read() { int out = 0; bool flag = false; register char cc = getchar(); while (cc < '0' || cc > '9') { if (cc == '-') flag = true; cc = getchar(); } while (cc >= '0' && cc <= '9') { out = (out << 3) + (out << 1) + (cc ^ 48); cc = getchar(); } return flag ? -out : out; } inline void write(int x, char ch) { if (x < 0) putchar('-'), x = -x; if (x == 0) putchar('0'); else { int num = 0; char cc[22]; while (x) cc[++num] = x % 10 + 48, x /= 10; while (num) putchar(cc[num--]); } putchar(ch); } const int N = 100010; int n, q, rt, nodeid, tr[N][2], sze[N], fa[N]; unsigned int arr[N], val[N], p[N]; char ch; void updata(int u) { sze[u] = sze[tr[u][0]] + sze[tr[u][1]] + 1; val[u] = val[tr[u][0]] * p[sze[tr[u][1]] + 1] + arr[u] * p[sze[tr[u][1]]] + val[tr[u][1]]; } void rotate(int x) { int y = fa[x], z = fa[y], opt1 = check(x), opt2 = check(y); fa[x] = z, tr[z][opt2] = x; fa[tr[x][opt1 ^ 1]] = y, tr[y][opt1] = tr[x][opt1 ^ 1]; fa[y] = x, tr[x][opt1 ^ 1] = y; updata(y), updata(x); } void splay(int x, int goal) { updata(x); while (fa[x] != goal) { int y = fa[x], z = fa[y]; if (z != goal) rotate(check(x) == check(y) ? y : x); rotate(x); } if (!goal) rt = x; } int find(int k) { if (k == 0) return 0; int u = rt; while (true) { if (k > sze[tr[u][0]] + 1) k -= sze[tr[u][0]] + 1, u = tr[u][1]; else if (k <= sze[tr[u][0]]) u = tr[u][0]; else return u; } } void ins(int k, int c) { int u = find(k), par = u, v = tr[par][1]; while (v) par = v, v = tr[par][0]; v = ++nodeid, sze[v] = 1, arr[v] = c; fa[v] = par, tr[par][par == u ? 1 : 0] = v, splay(v, 0); } void change(int k, int c) { int u = find(k); arr[u] = c, splay(u, 0); } unsigned int query(int l, int r) { if (l == 1 && r == n) return val[rt]; if (l == 1) return splay(find(r + 1), 0), val[tr[rt][0]]; if (r == n) return splay(find(l - 1), 0), val[tr[rt][1]]; int x = find(l - 1), y = find(r + 1); splay(x, 0), splay(y, x); return val[tr[y][0]]; } int main() { p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i - 1] * 29u; ch = getchar(); while (ch < 'a' || ch > 'z') ch = getchar(); while (ch >= 'a' && ch <= 'z') ins(n++, ch - 'a'), ch = getchar(); for (q = read(); q; q--) { ch = getchar(); while (ch != 'Q' && ch != 'R' && ch != 'I') ch = getchar(); if (ch == 'Q') { int x = read(), y = read(); int l = 0, r = n - max(x, y), ans = -1; while (l <= r) { int mid = (l + r) >> 1; if (query(x, x + mid) == query(y, y + mid)) l = mid + 1, ans = mid; else r = mid - 1; } write(ans + 1, '\n'); } else if (ch == 'R') { int x = read(); ch = getchar(); while (ch < 'a' || ch > 'z') ch = getchar(); change(x, ch - 'a'); } else { int x = read(); ch = getchar(); while (ch < 'a' || ch > 'z') ch = getchar(); ins(x, ch - 'a'); n++; } } return 0; }View Code
3.DP、各种比赛、知识点补充、trick的积累
4.数学
5.图
计划待补充
标签:ch,cc,while,mid,省选前,int,任务,计划,getchar 来源: https://www.cnblogs.com/Urushibara-Ruka/p/14380880.html