くろねこ @ 2019-07-18 18:29:07
rt, 第一组测试数据本地AC, 提交RE, 求dalao告知原因或者帮我查个错
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
#define debug printf("Time Test: %d\n", clock())
template <typename qwq> inline void read(qwq & x)
{
x = 0;
rg int f = 1;
rg char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
x *= f;
}
template <typename qaq> inline void print(qaq x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
#define lson son[0]
#define rson son[1]
class Slay
{
public:
Slay()
{
root = NULL;
}
inline void build(int n)
{
for (rg int i = 0; i <= n + 1; ++i) insert(i);
}
inline void insert(int val)
{
if (find(val) != NULL)
{
++ root -> cnt;
PushUp(root);
}
else if (root == NULL) root = newnode(val, NULL);
else Splay(insert(root, val), NULL);
}
inline void reserve(int l, int r)
{
++l, ++r;
Splay(kth(l - 1), NULL);
Splay(kth(r + 1), root);
reserve(root -> rson -> lson);
}
inline void output(int n)
{
for (rg int i = 1; i <= n; ++i) print(kth(i + 1) -> val), __space;
}
private:
const static int maxn = 233333;
struct node
{
node *fa, *son[2];
int siz, val, cnt;
bool res;
}*root;
inline node *newnode(int val, node *fa)
{
rg node *rt = new node;
rt -> siz = rt -> cnt = 1;
rt -> val = val, rt -> fa = fa;
rt -> res = false;
rt -> lson = rt -> rson = NULL;
return rt;
}
inline void freenode(node *x)
{
x -> fa = x -> lson = x -> rson = NULL;
x -> cnt = x -> val = x -> siz = 0;
x -> res = false;
delete x;
}
inline int size(node *x)
{
return x == NULL ? 0 : x -> siz;
}
inline void PushUp(node *x)
{
if (x != NULL) x -> siz = size(x -> lson) + size(x -> rson) + x -> cnt;
}
inline bool query_son(node *x)
{
if (x -> fa == NULL) return false;
return x -> fa -> rson == x;
}
inline node *insert(node *x, int val)
{
rg node *ret = x -> son[x -> val <= val];
if (ret == NULL) ret = x -> son[x -> val <= val] = newnode(val, x);
else ret = insert(ret, val);
PushUp(x);
return ret;
}
inline bool query_tag(node *x)
{
return x == NULL ? false : x -> res;
}
inline bool reserve(node *x)
{
if (x != NULL) x -> res ^= true;
}
inline void PushDown(node *x)
{
if (query_tag(x))
{
swap(x -> lson, x -> rson);
reserve(x -> lson), reserve(x -> rson);
x -> res = false;
}
}
inline void reconnect(node *fa, node *x, bool k)
{
if (fa != NULL) fa -> son[k] = x;
else root = x;
if (x != NULL) x -> fa = fa;
}
inline void rotate(node *x)
{
rg node *fa = x -> fa;
rg node *grandpa = fa -> fa;
rg bool k = query_son(x);
reconnect(fa, x -> son[k ^ 1], k);
reconnect(grandpa, x, query_son(fa));
reconnect(x, fa, k ^ 1);
PushUp(fa), PushUp(x);
}
inline void Splay(node *x, node *y)
{
if (x == y) return;
if (x == NULL) return;
while (x -> fa != y)
{
rg node *fa = x -> fa;
rg node *grandpa = fa -> fa;
PushDown(grandpa), PushDown(fa), PushDown(x);
if (grandpa == y) rotate(x);
else
{
if (query_son(fa) ^ query_son(x)) rotate(x), rotate(x);
else rotate(fa), rotate(x);
}
}
}
inline node *find(int val)
{
rg node *rt = root;
while (rt != NULL && rt -> val != val)
{
PushDown(rt);
rt = rt -> son[rt -> val <= val];
}
return rt;
}
inline node *kth(int k)
{
if (size(root) < k) return NULL;
rg node *rt = root;
while (rt != NULL)
{
PushDown(rt);
if (size(rt -> lson) < k)
{
k -= size(rt -> lson);
if (k <= rt -> cnt) return rt;
else k -= rt -> cnt, rt = rt -> rson;
}
else rt = rt -> lson;
}
}
}s;
int n, m, l, r;
int main()
{
read(n), read(m);
s.build(n);
for (rg int i = 1; i <= m; ++i) read(l), read(r), s.reserve(l, r);
s.output(n);
return 0;
}
by RoseKey @ 2019-07-18 18:40:10
%%%
by iPlayForSG @ 2019-07-18 18:43:23
%%%
by fxhfxh55555 @ 2019-07-18 18:43:52
%%%
by wwlw @ 2019-07-18 18:43:56
表示指针看着好难受
by Shinku721 @ 2019-07-18 18:47:53
%%%
by くろねこ @ 2019-07-18 18:50:55
@wwlw 把指针当作结构体下标凑合着看吧qwq
by Thomastine @ 2019-07-18 18:55:57
%%%
by Anonymous匿名者 @ 2019-07-18 19:09:36
现在萌新的水准越来越高了
by くろねこ @ 2019-07-18 19:20:18
我现在是真的懵了..
by くろねこ @ 2019-07-18 19:22:16
为什么bzoj loj 洛谷差距这么大啊