QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#920699#21403. 文艺平衡树Rong7#WA 1ms3840kbC++144.0kb2025-02-28 17:17:372025-02-28 17:17:43

Judging History

This is the latest submission verdict.

  • [2025-02-28 17:17:43]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-28 17:17:37]
  • Submitted

answer

// Go in my style.
// Not afraid to dark.

#include <bits/stdc++.h>
using namespace std;

clock_t sttime;
#define STCLOCK sttime = clock();
#define TIMENOW fprintf(stderr, "\nNOW TIME COSSEMED: %0.4lf\n", 1.0 * (clock() - sttime) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))

namespace io {
    int pos;
    inline int read(int &p = pos) {
        static bool v; static char c;
        p = 0, v = false, c = getchar();
        while (!isdigit(c)) {
            if (c == '-') v = true;
            c = getchar();
        }
        while (isdigit(c)) {
            p = (p << 1) + (p << 3) + (c - 48);
            c = getchar();
        }
        return p = v ? - p : p;
    }
    inline void write(int x) {
        static int sta[65], top; top = 0;
        if (x < 0) putchar('-'), x = - x;
        do sta[++top] = x % 10, x /= 10;
        while (x);
        while (top) putchar(sta[top--] + 48);
    }
}

const int N = 1e5;
int n, m, a[N + 5];

mt19937 mt(time(0));

struct Treap {
    int root, ls[N + 5], rs[N + 5], cnt[N + 5], tag[N + 5], tot;
    unsigned pri[N + 5]; int vl[N + 5];
    inline void push_up(int p) { cnt[p] = cnt[ls[p]] + cnt[rs[p]] + 1; }
    inline void put_tag(int p, int t) {
        if (t) {
            swap(ls[p], rs[p]);
            tag[p] ^= 1;
        }
    }
    inline void push_down(int p) {
        if (tag[p]) {
            if (ls[p]) put_tag(ls[p], 1);
            if (rs[p]) put_tag(rs[p], 1);
            tag[p] = 0;
        }
    }
    inline int new_node(int vv = 0) {
        ++tot, ls[tot] = rs[tot] = tag[tot] = 0, cnt[tot] = 1;
        pri[tot] = mt(), vl[tot] = vv;
        return tot;
    }
    int Rank(int p, int x) {
        if (!p) return 1;
        push_down(p);
        if (vl[p] < x) return cnt[ls[p]] + 1 + Rank(rs[p], x);
        return Rank(ls[p], x);
    }
    int Kth(int p, int k) {
        push_down(p);
        if (cnt[ls[p]] < k) {
            if (k - cnt[ls[p]] == 1) return p;
            return Kth(rs[p], k - cnt[ls[p]] - 1);
        }
        return Kth(ls[p], k);
    }
    pair<int, int> Split(int p, int k) {
        if (!p) return {0, 0};
        push_down(p);
        if (k <= cnt[ls[p]]) {
            auto res = Split(ls[p], k);
            ls[p] = res.second;
            cnt[p] = cnt[ls[p]] + cnt[rs[p]] + 1;
            return {res.first, p};
        } else {
            auto res = Split(rs[p], k - cnt[ls[p]] - 1);
            rs[p] = res.first;
            cnt[p] = cnt[ls[p]] + cnt[rs[p]] + 1;
            return {p, res.second};
        }
    }
    int Merge(int p1, int p2) {
        if (!p1 || !p2) return p1 | p2;
        push_down(p1), push_down(p2);
        if (pri[p1] < pri[p2]) {
            rs[p1] = Merge(rs[p1], p2);
            push_up(p1);
            return p1;
        } else {
            ls[p2] = Merge(p1, ls[p2]);
            push_up(p2);
            return p2;
        }
    }
    inline void Ins(int x) {
        int p = new_node(x), k = Rank(root, x);
        if (!root) root = p;
        else {
            int r1, r2; tie(r1, r2) = Split(root, k - 1);
            root = Merge(r1, p); root = Merge(root, r2);
        }
    }
    inline void rev(int l, int r) {
        int r1, r2, r3;
        tie(r1, r2) = Split(root, l - 1);
        tie(r2, r3) = Split(r2, r - l + 1);
        put_tag(r2, 1);
        root = Merge(r1, r2); root = Merge(root, r3);
    }
    void get(int p, vector<int> &A) {
        if (!p) return ;
        get(ls[p], A); A.emplace_back(vl[p]); get(rs[p], A);
    }
    inline void init() { root = tot = 0; }
    Treap() { init(); }
} T;

signed main() {
    STCLOCK

    io::read(n), io::read(m);
    for (int i = 1; i <= n; ++i) a[i] = i, T.Ins(i);
    for (int Times = 1, l, r; Times <= m; ++Times) {
        io::read(l), io::read(r);
        T.rev(l, r);
    }
    vector<int> id;
    T.get(T.root, id);
    for (int x : id) io::write(a[x]), putchar(' '); putchar('\n');

    TIMENOW
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3840kb

input:

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

output:

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

result:

wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1 2 4 17 16 6 15 5 18 19 20 21... 13 11 12 10 9 8 7 27 28 29 30 '