QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#854348 | #8704. 排队 | __zyx__ | 0 | 277ms | 7572kb | C++14 | 1.8kb | 2025-01-11 23:53:37 | 2025-01-11 23:53:41 |
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)), 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;
mt19937 Rand(2347);
int newnode() {
return ts++, t[ts] = {0, 0, Rand(), 1}, 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 != rt && x) {
if (t[t[x].fa].rs == 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 x, int pos) {
split(rt, pos, fx, fy);
fx = merge(fx, x);
rt = merge(fx, 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--) {
// cout << "ok";
int op, x, y; cin >> op >> x;
if (op == 1) insert(newnode(), 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: 0ms
memory: 3620kb
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: 3612kb
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 28 6 21 4 11 10 26 38 27 42 33 44 48 10 43 2 43 37 4 35 38 6 61 33 58 46 49 14 2 14 28 39 24 31 23 67 61 39 16 28 60 50 26 9 21 80 73 73 77 48 3 47 73 33 28 67 21 73 76 32 19 76 46 65 32 38 21 16 85 32 53 25 52 49 90 87 40 4 44 66 88...
result:
wrong answer 3rd lines differ - expected: '3', found: '2'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 115ms
memory: 7572kb
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: 98ms
memory: 6616kb
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: 277ms
memory: 6372kb
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 10 17 6 13 18 19 17 14 1 22 6 6 16 13 24 25 10 21 1 15 27 20 28 33 39 23 36 17 39 5 36 9 8 17 17 50 14 26 17 49 17 56 37 12 24 30 51 5 2 41 6 7 48 8 65 37 30 38 17 58 7 34 60 77 71 7 66 47 64 85 73 17 3 3 51 98 64 20 57 81 68 9 20 45 84 21 65 3 48 84 100...
result:
wrong answer 5th lines differ - expected: '2', found: '1'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%