QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#676628#21403. 文艺平衡树Poetry#WA 1ms3784kbC++231.8kb2024-10-25 22:35:502024-10-25 22:35:52

Judging History

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

  • [2024-10-25 22:35:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-10-25 22:35:50]
  • 提交

answer

#include <bits/stdc++.h>

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

std::mt19937_64 g(std::time(0));

constexpr int N = 1E5 + 5;

int n, m, tot, rt;

struct Treap {
	struct Node {
		int ls, rs;
		int sz, val;
		u64 rnd;
		int rev;
	} t[N];

	void apply(int x) {
		if (!x) return ;
		t[x].rev ^= 1;
		std::swap(t[x].ls, t[x].rs);
	}
	void push(int x) {
		if (x && t[x].rev) {
			apply(t[x].ls);
			apply(t[x].rs);
			t[x].rev = 0;
		}
	}
	void pull(int x) {
		t[x].sz = t[t[x].ls].sz + t[t[x].rs].sz + 1;
	}

	void split(int x, int k, int &u, int &v) {
		if (!x) {u = v = 0; return ;}
		push(x);
		if (t[t[x].ls].sz < k) u = x, split(t[x].rs, k - t[t[x].ls].sz - 1, t[x].rs, v);
		else v = x, split(t[x].ls, k, u, t[x].ls);
	}
	int merge(int x, int y) {
		if (!x || !y) return x ^ y;
		if (t[x].rnd > t[y].rnd) {
			push(x);
			t[x].rs = merge(t[x].rs, y);
			return pull(x), x;
		} else {
			push(y);
			t[y].ls = merge(x, t[y].ls);
			return pull(y), y;
		}
	}

	int newnode(int val) {
		int x = ++tot;
		t[x].ls = t[x].rs = 0;
		t[x].sz = 1; t[x].val = val;
		t[x].rnd = g();
		t[x].rev = 0;
		return x;
	}
	void add(int val) {
		rt = merge(rt, newnode(val));
	}

	void reverse(int l, int r) {
		int x, y;
		split(rt, l - 1, rt, x);
		split(x, r - l + 1, x, y);
		apply(x);
		rt = merge(rt, merge(x, y));
	}

	void print(int x) {
		if (!x) return ;
		push(x);
		print(t[x].ls);
		std::cout << t[x].val << " ";
		print(t[x].rs);
	}
} fhq;

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

 	std::cin >> n >> m;

 	for (int i = 1; i <= n; ++i) fhq.add(i);

 	while (m--) {
 		int l, r;
 		std::cin >> l >> r;
 		fhq.reverse(l, r);
 	}

 	fhq.print(rt);

	return 0;
}

详细

Test #1:

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

input:

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

output:

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