Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
44807 _ 数列操作4 C++ 通过 100 195 MS 12224 KB 2272 2022-02-10 16:34:09

Tests(10/10):


#include <bits/stdc++.h> using namespace std; constexpr int MXN = 200005; constexpr int MXH = 8; int val[MXN], height[MXN], nxt[MXN][MXH], len[MXN][MXH], temp1[MXH], temp2[MXH]; int N, ndsz; int read() { int x(0), p(1); char c(getchar()); while (c < '0' || c > '9') (c ^ '-' ? 0 : p = -p), c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x * p; } void write(int x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar((x % 10) | 48); } bool randb() { return (rand() & 0x7f) < 0x20; } int randh() { int h(0); while (randb() && h < MXH - 1) ++h; return h; } void init() { N = read(); ndsz = N + 2; for (int i(0); i != MXH; ++i) temp1[i] = 1; for (int i(2); i <= N + 1; ++i) { val[i] = read(); height[i] = randh(); for (int j(0); j <= height[i]; ++j) nxt[temp1[j]][j] = i, len[temp1[j]][j] = i - temp1[j], temp1[j] = i; } for (int i(0); i != MXH; ++i) nxt[temp1[i]][i] = 0, len[temp1[i]][i] = N + 2 - temp1[i]; } int query(int pos) { int cur(1); for (int i(MXH - 1); ~i; --i) { while (pos > len[cur][i]) pos -= len[cur][i], cur = nxt[cur][i]; } return val[nxt[cur][0]]; } void insert(int pos, int num) { int cur(1), dist(0); for (int i(MXH - 1); ~i; --i) { while (dist + len[cur][i] < pos) dist += len[cur][i], cur = nxt[cur][i]; temp1[i] = cur, temp2[i] = dist; } cur = ndsz++, val[cur] = num, height[cur] = randh(); for (int i(0); i <= height[cur]; ++i) nxt[cur][i] = nxt[temp1[i]][i], len[cur][i] = temp2[i] + len[temp1[i]][i] - pos + 1, nxt[temp1[i]][i] = cur, len[temp1[i]][i] = pos - temp2[i]; for (int i(height[cur] + 1); i != MXH; ++i) ++len[temp1[i]][i]; } int main() { srand(time(0)); init(); for (int opt, l, r, c; N--;) { opt = read(), l = read(), r = read(), c = read(); if (opt) { cout << query(r) << endl; } else { insert(l, r); } // for (int i(0); i != ndsz; ++i) { // cout << val[i] << ' '; // for (int j(0); j != MXH; ++j) // cout << '(' << nxt[i][j] << ',' << len[i][j] << "),"; // cout << endl; // } } return 0; }


测评信息: