QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128114#21403. 文艺平衡树1234567890#WA 2ms7632kbC++142.4kb2023-07-20 16:02:342023-07-20 16:02:35

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-20 16:02:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7632kb
  • [2023-07-20 16:02:34]
  • 提交

answer

/*
灏忓簾鐗╋紝杩欓兘涓嶄細 /cf
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define inf (ll)1e9
#define pii pair <ll, ll>
#define fr first
#define se second
const ll mod = 1e9 + 7;
char buf[1 << 21], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++)
inline ll read() {
	ll x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
inline void write(ll x) {
	if(x < 0) x = -x, putchar('-');
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}
struct fhq {
	#define ls(x) ch[x][0]
	#define rs(x) ch[x][1]
	ll ch[100005][2], tag[100005], sp[100005], a[100005], siz[100005];
	ll Rt;
	inline void push_rev(ll x) {
		swap(ls(x), rs(x));
		tag[x] ^= 1;
	}
	inline void push_up(ll x) {
		siz[x] = siz[ls(x)] + siz[rs(x)] + 1;
	}
	inline void push_tag(ll x) {
		if(tag[x]) {
			if(ls(x)) push_rev(ls(x));
			if(rs(x)) push_rev(rs(x));
			tag[x] = 0;
		}
	}
	inline ll Merge(ll x, ll y) {
		if(!x || !y) return x | y;
		push_tag(x), push_tag(y);
		if(sp[x] < sp[y]) {
			rs(x) = Merge(rs(x), y);
			push_up(x);
			return x;
		}
		else {
			ls(y) = Merge(x, ls(y));
			push_up(y);
			return y;
		}
	}
	inline void split(ll x, ll k, ll &l, ll &r) {
		if(!x) {
			l = r = 0;
			return ;
		}
		push_tag(x);
		if(siz[ls(x)] + 1 <= k) {
			l = x;
			split(rs(x), k - (siz[ls(x)] + 1), rs(l), r);
			push_up(l);
		}
		else {
			r = x;
			split(ls(x), k, l, ls(r));
			push_up(r);
		}
	}
	inline void update(ll l, ll r) {
		ll L, x, R;
		split(Rt, l - 1, L, x), split(x, r - l + 1, x, R);
		push_rev(x);
		Rt = Merge(Merge(L, x), R);
	}
	inline void print(ll x) {
		if(!x) return ;
		push_tag(x);
		print(ls(x));
		write(a[x]), putchar(' ');
		print(rs(x));
	}
}T;
ll n, m;
int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	srand(time(NULL));
	default_random_engine e(1ll * rand() * rand());
	uniform_int_distribution <ll> R(1, inf);
	n = read(), m = read();
	for(ll i = 1; i <= n; i++) T.a[i] = i, T.sp[i] = R(e);
	for(ll i = 1; i <= n; i++) T.Rt = T.Merge(T.Rt, T.a[i]);
	while(m--) {
		ll l = read(), r = read();
		T.update(l, r);
	} 
	T.print(T.Rt); 
	return 0;
}
/*
*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7632kb

input:

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

output:

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

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 4 6 16 15 14 13 9 8 7 17...4 25 5 26 27 28 29 30 12 11 10 '