QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#854364 | #8704. 排队 | __zyx__ | 0 | 276ms | 7140kb | C++14 | 1.8kb | 2025-01-12 00:05:33 | 2025-01-12 00:05:39 |
Judging History
answer
#include <bits/stdc++.h>
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;
t[ls(k)].fa = t[rs(k)].fa = k;
t[k].w = min({t[ls(k)].w, t[rs(k)].w, k});
}
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));
else x = k, split(rs(k), w - t[ls(k)].siz - 1, rs(x), y);
pushup(k);
}
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;
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 || k < t[ls(k)].w) return find(ls(k), w);
else return t[ls(k)].siz + 1 + find(rs(k), w);
}
int rnk(int x) {
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; // cout << x << '\n';
}
return res;
}
void move(int x, int y) {
int rkx = rnk(x);
split(rt, rkx - 1, fx, fy);
split(fy, find(fy, fy), fz, fy);
rt = merge(fx, fy);
int rky = rnk(y);
split(rt, rky - 1, fx, fy);
split(fy, find(fy, fy), 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);
}
int 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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 1ms
memory: 3676kb
input:
0 8 1 0 1 1 1 2 3 2 2 2 0 3 1 3 2 3 3
output:
2 3 1 2
result:
ok 4 lines
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 3624kb
input:
0 485 1 0 2 1 0 2 1 0 3 1 3 1 1 0 1 1 3 3 2 3 2 2 2 1 2 2 1 2 2 0 3 1 3 1 3 1 1 0 2 3 0 1 2 3 3 1 3 2 3 2 1 1 2 2 0 1 3 2 3 0 2 1 0 1 1 2 8 6 2 3 0 3 3 2 4 1 1 4 3 2 1 0 1 5 1 4 2 3 2 2 7 4 3 5 1 7 1 8 2 7 5 3 14 3 2 2 6 2 3 13 1 0 3 11 1 13 3 1 3 4 1 4 2 15 0 2 15 9 2 17 16 3 13 1 17 2 17 12 3 3 3 ...
output:
1 1 2 1 1 1 3 7 6 11 8 12 10 3 1 10 12 5 12 15 19 25 22 22 12 1 16 33 4 25 9 15 7 21 28 22 32 39 31 33 3 35 7 27 30 6 28 31 55 61 28 65 42 45 9 3 9 33 36 72 27 17 19 65 72 73 54 59 41 77 5 82 80 63 63 39 36 73 35 82 5 10 75 27 85 88 22 53 69 29 60 7 88 53 47 96 38 62 36 61 61 15 103 75 58 38 69 104 ...
result:
wrong answer 3rd lines differ - expected: '3', found: '2'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 114ms
memory: 6860kb
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:
1 1 1 1 1 2 4 4 3 6 7 8 10 7 4 7 6 10 4 6 11 7 4 3 15 8 17 6 6 1 4 16 21 7 7 1 26 10 9 24 9 21 26 2 22 27 4 8 5 23 25 16 26 38 37 9 26 4 4 12 18 4 39 13 2 28 22 17 40 12 29 3 36 38 1 18 51 23 42 14 18 35 44 21 24 49 50 5 39 5 47 13 51 37 60 6 12 23 45 25 22 54 26 65 31 6 6 10 8 62 66 39 65 63 14 33 ...
result:
wrong answer 6th lines differ - expected: '1', found: '2'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 99ms
memory: 7140kb
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:
2 3 2 2 4 3 4 2 2 8 2 10 2 10 8 2 8 9 8 11 3 4 3 8 2 11 9 5 4 6 6 9 5 15 13 12 6 9 6 12 10 2 4 6 10 9 16 4 15 13 13 7 5 5 11 21 7 1 6 4 10 1 15 20 2 17 12 1 24 6 15 13 7 10 17 2 19 9 19 19 12 5 18 16 21 19 26 12 25 21 19 10 14 24 8 8 14 16 32 8 14 33 30 14 6 3 20 21 37 22 25 7 18 27 28 35 37 18 33 6...
result:
wrong answer 2nd lines differ - expected: '2', found: '3'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 276ms
memory: 6848kb
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:
1 2 4 3 1 3 4 4 2 1 3 3 3 1 1 4 5 7 3 3 4 8 3 14 3 11 7 20 21 19 7 5 3 6 6 15 13 4 14 18 29 1 23 27 6 28 20 16 8 33 2 35 43 18 34 19 33 33 26 22 16 25 2 24 29 10 22 34 51 57 48 47 12 46 16 14 6 9 38 23 39 18 33 38 55 32 67 6 38 39 15 7 12 6 25 1 1 30 18 8 106 46 89 72 17 51 12 98 52 71 1 94 76 34 72...
result:
wrong answer 5th lines differ - expected: '2', found: '1'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%