QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482335#21403. 文艺平衡树hcngWA 0ms5620kbC++142.1kb2024-07-17 18:58:272024-07-17 18:58:27

Judging History

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

  • [2024-07-17 18:58:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5620kb
  • [2024-07-17 18:58:27]
  • 提交

answer

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

char *p1, *p2, buf[1000000];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
inline int read() {int x=0;char c=gc();while(!isdigit(c))c=gc();while(isdigit(c))x=x*10+c-'0',c=gc();return x;}
#define pc(c) putchar(c)
void write(int x) {if(x>9)write(x/10);pc('0'+x%10);}

int n, m;

struct Treap {
    int rt, tot;
    int val[100010], key[100010];
    int fa[100010], siz[100010];
    int ch[100010][2], tag[100010];
    
    inline int create(int v){val[++tot]=v,key[tot]=rand(),siz[tot]=1,fa[tot]=ch[tot][0]=ch[tot][1]=0;return tot;}
    inline void pushup(int x){siz[x]=siz[ch[x][0]]+siz[ch[x][1]]+1;}
    inline void pushr(int x){tag[x]^=1,swap(ch[x][0],ch[x][1]);}
    inline void pushdown(int x){if(tag[x])pushr(ch[x][0]),pushr(ch[x][1]),tag[x]=0;}
    void split(int x, int k, int &a, int &b) {
        if (!x) return (void)(a = b = 0);
        pushdown(x);
        if (k <= siz[ch[x][0]])
            b = x, split(ch[x][0], k, a, ch[x][0]);
        else
            a = x, split(ch[x][1], k - siz[ch[x][0]] - 1, ch[x][1], b);
        pushup(x);
    }
    int merge(int x, int y) {
        if (!x || !y) return x | y;
        if (key[x] < key[y]) {
            pushdown(x);
            ch[x][1] = merge(ch[x][1], y);
            pushup(x);
            return x;
        } else {
            pushdown(y);
            ch[y][0] = merge(x, ch[y][0]);
            pushup(y);
            return y;
        }
    }
    inline void flip(int l, int r) {
        int x, y, z;
        split(rt, r, y, z);
        split(y, l - 1, x, y);
        pushr(y);
        rt = merge(x, merge(y, z));
    }
    void print(int x) {
        if (!x) return;
        print(ch[x][0]);
        write(val[x]); pc(' ');
        print(ch[x][1]);
    }
} T;

int main() {
    n = read(), m = read();
    for (int i = 1; i <= n; i++) {
        T.rt = T.merge(T.rt, T.create(i));
    }
    for (int i = 1; i <= m; i++) {
        int l = read(), r = read();
        T.flip(l, r);
    }
    T.print(T.rt); pc('\n');
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5620kb

input:

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

output:

1 2 4 17 15 16 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:

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 15 16 6 5 18 19 20 21... 13 12 11 10 9 8 7 27 28 29 30 '