rt,vjudge链接
正常的块状链表思路,块与块之间以链表链接,块本身暴力数组维护
//#pragma GCC optimize (2)
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, M = 4e2 + 50;
int read () {
int x = 0, y = 1;
char c = getchar ();
while (c < '0' || c > '9') {
if (c == '-') y = -1;
c = getchar ();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar ();
}
return x * y;
}
void write (int x) {
if (x < 0) putchar ('-'), x = -x;
if (x > 9) write (x / 10);
putchar (x % 10 + '0');
}
int n, res = 1;
struct node {
int l, r, sz;
int pre, nxt;
vector <int> v;
};
node a[M];
signed main () {
n = read ();
a[1].l = 1;
for (int i = 1; i <= n; i ++ ) {
int k = read ();
if (a[res].sz == M) a[res].r = i - 1, res ++ , a[res].l = i, a[res - 1].nxt = res, a[res].pre = res - 1;
a[res].v.push_back (k), a[res].sz ++ ;
}
a[res].r = n;
while (n -- ) {
int opt = read (), l = read (), r = read (), c = read ();
if (opt == 0) {
int j = 1;
while (a[j].r < l) j = a[j].nxt;
for (int i = 0; i < a[j].v.size (); i ++ )
if (a[j].l + i == l) {
int k = a[j].v.size () - 1;
a[j].v.push_back (a[j].v[k]);
for (k = a[j].v.size () - 2; k > i; k -- ) a[j].v[k] = a[j].v[k - 1];
a[j].v[i] = r;
a[j].sz ++ , a[j].r ++ ;
k = j;
while (a[k].sz) a[k].l ++ , a[k].r ++ , k = a[k].nxt;
break;
}
// if (a[j].sz == 2 * M) {
// res ++ ;
// a[res].pre = j, a[res].nxt = a[j].nxt, a[a[j].nxt].pre = res, a[j].nxt = res;
// a[res].l = a[j].l + M, a[res].r = a[j].r, a[j].r = a[j].l + M - 1;
// a[res].sz = a[j].sz = M;
// for (int i = M; i < a[j].v.size (); i ++ ) a[res].v.push_back (a[j].v[i]);
// while (a[j].v.size () > M) a[j].v.erase (a[j].v.end ());
// }
} else {
int j = 1;
while (a[j].r < r) j = a[j].nxt;
for (int i = 0; i < a[j].v.size (); i ++ )
if (a[j].l + i == r) {
write (a[j].v[i]), putchar ('\n');
break;
}
}
}
return 0;
}
注释掉的部分是为了防止被卡而写的分裂,因为没过随机数据的模板而注释掉了,但为什么还是错的呢?
如果分裂的部分也有问题也尽请指正qwq