QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#854900 | #8704. 排队 | __zyx__ | 0 | 0ms | 0kb | C++14 | 1.9kb | 2025-01-12 10:48:03 | 2025-01-12 10:48:09 |
answer
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N = 3e5 + 5;
struct node {
int ls, rs, rd, siz, fa, w;
} t[N];
#define ls(k) t[k].ls
#define rs(k) t[k].rs
void pushup(int k) {
t[k].siz = t[ls(k)].siz + t[rs(k)].siz + 1;
if (ls(k)) t[ls(k)].fa = k;
if (rs(k)) t[rs(k)].fa = k;
t[k].w = min({t[ls(k)].w, t[rs(k)].w, k});
// assert(t[k].w);
}
void split(int k, int w, int &x, int &y) {
if (!k) return x = y = 0, void();
if (t[ls(k)].siz >= w) y = k, split(ls(k), w, x, ls(y)), pushup(y);
else x = k, split(rs(k), w - t[ls(k)].siz - 1, rs(x), y), pushup(x);
}
int merge(int x, int y) {
if (!x || !y) return x | y;
if (t[x].rd > t[y].rd) return rs(x) = merge(rs(x), y), pushup(x), x;
else return ls(y) = merge(x, ls(y)), pushup(y), y;
}
int ts, rt, fx, fy, fz, ft, fu;
mt19937 Rand(2347);
int newnode() {
return ts++, t[ts] = {0, 0, Rand(), 1, 0, ts}, ts;
}
int find(int k, int w) {
if (!k) return 0;
if (k < w || w > t[ls(k)].w) return find(ls(k), w);
else return t[ls(k)].siz + 1 + find(rs(k), w);
}
int rnk(int x) {
if (!x) return 0;
int res = t[ls(x)].siz + 1;
while (x) {
if (rs(t[x].fa) == x)
res += t[ls(t[x].fa)].siz + 1;
x = t[x].fa;
}
split(rt, res - 1, fx, fy);
assert(fy == x); rt = merge(fx, fy);
return res;
}
void move(int x, int y) {
split(rt, rnk(x) - 1, fx, fz);
split(fz, find(fz, x), fz, fy);
rt = merge(fx, fy);
split(rt, rnk(y), fx, ft);
split(ft, find(ft, x), ft, fy);
rt = merge(merge(fx, ft), merge(fz, fy));
}
void insert(int pos) {
split(rt, pos, fx, fy);
rt = merge(merge(fx, newnode()), fy);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int sub, n; cin >> sub >> n; t[0].w = N;
while (n--) {
int op, x, y; cin >> op >> x;
if (op == 1) insert(rnk(x));
else if (op == 2) cin >> y, move(x, y);
else cout << rnk(x) << '\n';
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
0 8 1 0 1 1 1 2 3 2 2 2 0 3 1 3 2 3 3
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #5:
score: 0
Runtime Error
input:
1 298913 1 0 3 1 3 1 3 1 3 1 3 1 1 0 1 0 3 3 1 2 1 2 3 5 3 5 1 1 1 3 1 4 3 3 1 3 1 6 3 7 3 2 3 5 3 8 3 2 1 8 3 3 1 4 3 2 3 7 1 3 3 4 1 10 3 14 3 13 1 12 3 4 1 8 1 15 1 16 3 9 3 14 3 10 3 8 3 7 1 16 1 15 3 16 3 13 1 19 3 13 3 1 3 14 1 18 1 22 3 8 1 17 3 18 3 9 1 18 3 9 3 1 1 20 3 11 3 5 3 2 3 22 1 22...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #20:
score: 0
Runtime Error
input:
2 298235 1 0 1 1 3 2 1 0 1 3 3 4 3 3 3 3 3 2 3 4 3 2 3 3 1 2 3 3 1 4 1 2 1 1 3 5 3 8 1 5 1 9 3 10 3 8 3 10 3 5 3 8 3 5 1 2 1 9 3 5 3 7 3 12 3 3 1 6 3 4 3 3 3 11 3 8 3 9 3 7 3 6 3 4 1 12 1 11 3 13 3 13 1 11 3 16 3 6 3 14 3 9 3 5 3 13 1 9 1 17 3 16 3 13 3 5 3 15 3 8 3 4 3 13 1 18 3 15 3 16 3 19 3 4 1 ...
output:
result:
Subtask #4:
score: 0
Runtime Error
Test #35:
score: 0
Runtime Error
input:
3 299743 1 0 1 1 3 1 1 2 3 2 1 0 3 3 3 2 3 1 3 2 2 2 1 3 3 3 3 3 4 3 1 3 2 3 2 2 1 0 3 2 3 1 3 1 1 0 3 2 1 2 1 1 3 2 2 5 2 1 6 1 0 2 5 2 1 7 3 8 3 5 3 5 2 7 5 2 9 4 3 5 3 8 2 6 2 2 3 0 2 2 0 1 1 2 3 1 1 8 2 7 0 3 3 1 12 2 13 9 1 5 2 2 1 2 14 13 1 12 2 1 0 2 12 10 2 15 12 1 0 1 6 3 6 2 3 2 2 17 6 3 4...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%