灵异现象
查看原帖
灵异现象
914572
zhx20081129楼主2024/7/19 18:41

不开O2,RE on 3,5,6 ,7,8,9,10,11,12

开O2,MLE on 3,5,6 ,7,8,9,10,11,12

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int cnt, root;
struct treeNode {
	int rk, pri, ls, rs, size, lazy;
}t[N];
void newNode(int x/*排名*/) {
	t[++cnt] = { x,rand(),0,0,1,0 };
}
void update(int u) {
	t[u].size = t[t[u].ls].size + t[t[u].rs].size + 1;
}
void pushdown(int u) {
	if (t[u].lazy) {
		swap(t[u].ls, t[u].rs);
		t[t[u].ls].lazy ^= 1;
		t[t[u].rs].lazy ^= 1;
		t[u].lazy = 0;
	}
}
void split(int u, int x/*排名*/, int& L,int&  R) {
	if (u == 0) { L = R = 0; return; }
	pushdown(u);
	if (t[t[u].ls].size + 1 <= x) {
		L = u;
		split(t[u].rs, x - (t[t[u].ls].size + 1), t[u].rs, R);
	}
	else {
		R = u;
		split(t[u].ls, x , L, t[u].ls);
	}
	update(u);
}
int Merge(int L, int R) {
	if (L == 0 || R == 0) return L + R;
	if (t[L].pri > t[R].pri) {
		pushdown(L);
		t[L].rs = Merge(t[L].rs, R);
		update(L);  return L;
	}
	else {
		pushdown(R);
		t[R].ls = Merge(L,t[R].ls);
		update(R);  return R;
	}
}
void inorder(int u) {
	if (u == 0) return ;
	pushdown(u);
	inorder(t[u].ls);
	printf("%d ", t[u].rk);
	inorder(t[u].rs);
}
int main() {
	srand(time(0));
	int n, m;  cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		newNode(i);
		root = Merge(root, cnt);
	}
	while (m--) {
		int x, y; cin >> x >> y;
		int L, R, p;
		split(root, y, L, R);
		split(L, x - 1, L, p);
		t[p].lazy ^= 1;
		root=Merge(Merge(L, p), R);
	}
	inorder(root);
	return 0;
}
2024/7/19 18:41
加载中...