BZOJ 3052 WC 2013 糖果公園

2022-05-11 23:35:11 字數 1524 閱讀 1275

對樹的dfs序分塊,開啟了新世界的大門233

第一關鍵字是l所在的塊,第二關鍵字是r所在的塊,第三關鍵字是時間,分完塊後暴力莫隊即可

#include#include#include#includeusing namespace std;

typedef long long ll;

const int n = 100003;

void read(int &k)

bool vis[n];

ll a[n], ans = 0;

struct time time[n];

struct edge e[n << 1];

struct node q[n];

int cal[n], n, m, q, v[n], w[n], f[n][17], deep[n], bel[n << 1];

int point[n], color[n], colorchange[n], pos[n << 1], l[n], r[n], cnt = 0;

void ins(int x, int y)

void _(int x, int fa)

for(int tmp = point[x]; tmp; tmp = e[tmp].nxt)

if (e[tmp].to != fa)

pos[r[x] = ++cnt] = x;

}int lca(int x, int y)

void update(int x)

else

vis[x] = !vis[x];

}void change(int a, int b)

else color[a] = b;

}void timechange(int &a, int b)

while (a > b)

}bool cmp(node a, node b)

int main()

for(int i = 1; i <= n; ++i) read(color[i]), colorchange[i] = color[i];

cnt = 0;

_(1, 0);

for(int i = 1; i <= q; ++i) ; colorchange[u] = v;}

else ;

else q[++tmp] = (node) ;

} }int nn = n << 1, sq = pow(nn, 2.0 / 3) * 0.5, sign = 0; cnt = 1;

for(int i = 1; i <= nn; ++i) }

sort(q + 1, q + tmp + 1, cmp);

int l = 1, r = 0, now = 0, tol, tor;

for(int i = 1; i <= tmp; ++i)

for(int i = 1; i <= tmp; ++i) printf("%lld\n", a[i]);

return 0;

}

dfs序分塊戰術核飛彈速度超快~

BZOJ 3052 wc2013 糖果公園

蒟蒻去做糖果公園了qaq 講道理速度能排rk11很開心啊 其實前人之述備矣 複雜度分析 推薦一波棟爺爺的題解 帶修改莫隊其實就是多一維時間 所以你需要資瓷修改和撤銷修改 然後就跟沒修改的莫隊其實差不多了 關於樹上莫隊 很明顯就是用dfs序這個套路 發現出現次數為奇數次的才會算到 棟老師題解那裡也有說...

BZOJ 3052 wc2013 糖果公園

讀題很容易知道這就是一道簡單的樹上帶修改莫隊,樹上待修改莫隊只要將待修改莫隊和樹上莫隊結合起來使用就可以了。感謝darkbzoj include include include include include include include include set include include i...

bzoj3052 wc2013 糖果公園

time limit 200 sec memory limit 512 mb submit 1438 solved 749 submit status discuss sample input 84131 2784 分析 沒想到這能用莫隊來做.先看資料,10w,應該是nlogn的演算法?時限有200...