Lolierl @ 2021-08-01 19:40:15
我的替罪羊树,过了普通版,代码基本没改
一直全部Re,调数组大小啥都不好使,下了数据本机也能过,然后我想看看到底是哪出问题了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#define ls b[t].ch[0]
#define rs b[t].ch[1]
using namespace std;
const int N = 4e5 + 5;
const double M = 0.75;
struct ScT
{
int d, ch[2], size, num;
}b[N];
int n, m, cnt, l, r, q[N * 2], w[N], a[N], c[N], tt, root;
bool check(int t)
{
return 1;
}
int newnode()
{
int t;
t = ++cnt;
b[t].d = ls = rs = 0;
b[t].size = b[t].num = 1;
return t;
}
void pushup(int t)
{
b[t].size = b[ls].size + b[rs].size + b[t].num;
}
void dfs1(int t)
{
if(ls)dfs1(ls);
if(b[t].num){w[++tt] = b[t].d; a[tt] = b[t].num; }
if(rs)dfs1(rs);
q[++r] = t;
}
int dfs2(int l, int r)
{
if(l > r)return 0;
int t = newnode();
int m = (l + r) >> 1;
ls = dfs2(l, m - 1);
b[t].d = w[m]; b[t].num = a[m];
rs = dfs2(m + 1, r);
pushup(t);
return t;
}
int rebuild(int t, int fa)
{
tt = 0;
//dfs1(t);
}
void insert(int t, int x, int fa)
{
if(x == b[t].d)
b[t].num++;
else if(x < b[t].d)
if(ls)insert(ls, x, t); else{ls = newnode(); b[ls].d = x; }
else
if(rs)insert(rs, x, t); else{rs = newnode(); b[rs].d = x; }
pushup(t);
rebuild(0,0)//这里
}
int main()
{
scanf("%d%d", &n, &m);
l = 1; r = 0;
root = newnode(); scanf("%d", &b[root].d);
for(int i = 2; i <= n; i++)
{
scanf("%d", &c[i]);
insert(root, c[i], 0);
}/*
int last = 0, op, x, d, ans = 0;
for(int i = 1; i <= m; i++)
{
scanf("%d%d", &op, &x);
x ^= last;
if(op == 1)
insert(root, x, 0);
else if(op == 2)
del(root, x, 0);
else if(op == 3)
{
d = getrank(root, x) + 1;
last = d; ans ^= d;
}
else if(op == 4)
{
d = getd(root, x);
last = d; ans ^= d;
}
else if(op == 5)
{
d = getd(root, getrank(root, x));
last = d; ans ^= d;
}
else if(op == 6)
{
d = getd(root, getrank(root, x) + getsum(root, x) + 1);
last = d; ans ^= d;
}
}
printf("%d\n", ans); */
return 0;
}
注释掉了所有的查询和重建,rebuild里面什么都不剩
然后有一个rebuild(0,0)就是re,删掉就是wa
https://www.luogu.com.cn/record/54722749
https://www.luogu.com.cn/record/54722733
不是很能理解
by aaaaaawsl @ 2021-08-03 17:57:45
我估计应该还是数组大小的问题,我用的是Treap,数组开了2000005才过