QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341540#21403. 文艺平衡树orz_z#WA 0ms3920kbC++141.9kb2024-02-29 19:39:532024-02-29 19:39:53

Judging History

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

  • [2024-02-29 19:39:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3920kb
  • [2024-02-29 19:39:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
 // #define int long long
#define F(i, l, r) for(int i = (l); i <= (r); ++i)
#define dF(i, r, l) for(int i = (r); i >= (l); --i)

int ri() {
	int x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = x* 10 + c - 48;
		c  = getchar();
	} return x * f;
}

const int _ = 1.1e6 + 5;
const int mod = 1e9 + 9;

int cnt;

struct node {
	int lc, rc, val, tg, rd, sz;
} tr[_];

void up(int o) {
	tr[o].sz = tr[tr[o].lc].sz + tr[tr[o].rc].sz + 1;
}
int New(int x) {
	int nw = ++cnt;
	tr[nw].lc = tr[nw].rc = tr[nw].tg = 0;
	tr[nw].val = x;
	tr[nw].rd = rand();
	return nw;
}

void pd(int o) {
	if(tr[o].tg) {
		swap(tr[o].lc, tr[o].rc);
		tr[tr[o].lc].tg ^= 1, tr[tr[o].rc].tg ^= 1;
		tr[o].tg = 0;
	}
}

void split(int rt, int val, int &x, int &y) {
	if(!rt) return x = y = 0, void();
	pd(rt);
	if(tr[tr[rt].lc].sz + 1 <= val) {
		x = rt;
		split(tr[rt].rc, val - tr[tr[rt].lc].sz - 1, tr[rt].rc, y);
		up(x);
	} else {
		y = rt;
		split(tr[rt].lc, val, x, tr[rt].lc);
		up(y);
	}
}

int merge(int x, int y) {
	if(!x || !y) return x + y;
	if(tr[x].rd < tr[y].rd) {
		pd(x);
		tr[x].rc = merge(tr[x].rc, y);
		up(x);
		return x;
	} else {
		pd(y);
		tr[y].lc = merge(x, tr[y].lc);
		up(y);
		return y;
	}
}

int Rt;

void ins(int val) {
	Rt = merge(Rt, New(val));
}

void dbg(int Rt) {
	if(!Rt) return;
	pd(Rt);
	dbg(tr[Rt].lc);
	printf("%d ", tr[Rt].val);
	dbg(tr[Rt].rc);
}
int n, m;

signed main() {
	srand(time(0) + rand());
	srand(time(0) + rand());
	srand(time(0) + rand());
	n = ri(), m = ri();
	F(i, 1, n) ins(i);
	while(m--) {
		int l = ri(), r = ri();
		int x, y, z;
		split(Rt, l - 1, x, y);
		split(y, r, y, z);
		tr[y].tg ^= 1;
		Rt = merge(merge(x, y), z);
	}
	dbg(Rt);
	cout << '\n';
}

詳細信息

Test #1:

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

input:

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

output:

1 2 3 18 17 16 15 14 13 12 11 10 9 8 7 21 22 23 24 25 26 27 28 5 4 19 20 6 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 3 18 17 16 15 14 13 12 11 ... 25 26 27 28 5 4 19 20 6 29 30 '