QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129969#21403. 文艺平衡树jrjyy#WA 1ms3608kbC++201.5kb2023-07-23 11:10:112023-07-23 11:10:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 11:10:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3608kb
  • [2023-07-23 11:10:11]
  • 提交

answer

/* fhq-treap.cpp */
#include <bits/stdc++.h>

using i64 = long long;
std::mt19937 rnd;
struct Node {
    Node *l = nullptr, *r = nullptr;
    int s = 0, v = 0; bool t = false; unsigned w = rnd();
} *null;
Node *newNode(int v) { return new Node{null, null, 1, v, false, rnd()}; }
void pull(Node *u) { u->s = 1 + u->l->s + u->r->s; }
void apply(Node *u) {
    std::swap(u->l, u->r), u->t ^= 1;
}
void push(Node *u) {
    if (u->t) apply(u->l), apply(u->r), u->t = false;
}
void split(Node *u, int p, Node *&x, Node *&y) {
    if (u == null) return x = y = null, void();
    push(u);
    if (p <= u->l->s) y = u, split(u->l, p, x, y->l), pull(u);
    else x = u, split(u->r, p - u->l->s - 1, x->r, y), pull(u);
}
Node *merge(Node *u, Node *v) {
    if (u == null || v == null) return u == null ? v : u;
    push(u), push(v);
    if (u->w < v->w) return u->r = merge(u->r, v), pull(u), u;
    else return v->l = merge(u, v->l), pull(v), v;
}
void print(Node *u) {
    if (u == null) return;
    print(u->l), std::cout << u->v + 1 << ' ', print(u->r);
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    null = new Node{}, null->l = null->r = null, null->s = 0;

    int n, q; std::cin >> n >> q;

    Node *rt = null;
    for (int i = 0; i < n; ++i) rt = merge(rt, newNode(i));

    while (q--) {
        int l, r; std::cin >> l >> r, --l;
        Node *x, *y, *z;
        split(rt, r, y, z), split(y, l, x, y), apply(y);
        rt = merge(merge(x, y), z);
    }

    print(rt);

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

input:

30 5
7 26
7 18
5 9
4 15
3 15

output:

1 2 4 17 16 15 6 5 18 19 20 21 22 23 3 24 25 26 14 13 12 11 10 9 8 7 27 28 29 30 

result:

ok single line: '1 2 4 17 16 15 6 5 18 19 20 21... 13 12 11 10 9 8 7 27 28 29 30 '

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3480kb

input:

100 10
9 29
10 68
7 72
15 73
57 79
4 39
11 69
45 61
1 42
15 21

output:

5 4 44 43 45 47 46 42 41 40 39 38 37 36 78 79 31 32 33 34 35 77 76 75 74 23 22 24 21 20 18 19 54 2 3 48 49 50 51 52 53 1 6 72 63 64 65 66 67 68 71 70 69 28 27 26 25 73 7 29 8 62 60 61 59 58 57 56 55 17 16 15 14 13 12 11 10 9 30 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

result:

wrong answer 1st lines differ - expected: '5 4 47 46 45 44 43 42 41 40 39... 91 92 93 94 95 96 97 98 99 100', found: '5 4 44 43 45 47 46 42 41 40 39...91 92 93 94 95 96 97 98 99 100 '