"Bzoj 3531" "Sdoi 2014" Travel Tree chain split

Source: Internet
Author: User

Because there is a $10^5$ religion, you need to open $10^5$ a line tree.

Usually open the line of the tree is "full" binary tree, but in this topic represents a religious line of the section tree jurisdiction of the range there are many points do not belong to this religion, also do not have to "extend the branches to this point", so this is similar to the chairman of the tree array dynamic open point to build $10^5$ only a few "branches" of the Maintain the weight chain on it.

The $l,r,l,r$ of the line-segment tree has been tuned for a long time. $qaq$ $so $ $SAD $

#include <cstdio> #include <cstring> #include <algorithm> #define READ (x) x=getint () #define N 100003using namespace Std;inline int getint () {int k = 0, fh = 1; char c = GetChar (); c < ' 0 ' | | c > ' 9 '; c = GetChar ()) if (c = = '-') FH =-1; for (; c >= ' 0 ' && C <= ' 9 '; c = GetChar ()) K = k * + C-' 0 '; return k * FH; struct Tree {int L, R, MA, SM;} t[4000010];struct G {int nxt, to;}  E[n << 1];int Root[n], point[n], cnt = 0, N, Q, W[n], c[n], sz[n], son[n], Up[n];int deep[n], fa[n], watch[n];inline void ins (int x, int y) {e[++cnt].nxt = point[x]; e[cnt].to = y; POINT[X] = cnt;} inline void _ (int x) {Sz[x] = 1;for (int tmp = point[x]; tmp; tmp = E[TMP].NXT) {int v = e[tmp].to;if (v = = Fa[x]) continue ; Fa[v] = x;deep[v] = deep[x] + 1;_ (v), if (Sz[v] > Sz[son[x]]) son[x] = v;sz[x] + = Sz[v];}} inline void __ (int x) {Watch[x] = ++cnt;if (!son[x]) return;up[son[x]] = up[x];__ (son[x]); for (int tmp =point[x]; TMP; TMP = e[tmp].nxt) {int v = e[tmp].to;if (v = = Fa[x] | | v = = Son[x]) continue;up[v] = v;__ (v);}} inline void pushup (int pos) {T[pos].sm = T[t[pos].l].sm + T[t[pos].r].sm; t[pos].ma = Max (t[t[pos].l].ma, t[t[pos].r].ma);} inline void update (int &pos, int l, int r, int to, int num) {if (pos = = 0) pos = ++cnt;if (L = = r) {t[pos].ma = T[pos] . SM = num; return;} int mid = (L + R) >> 1;if (to <= mid) update (T[POS].L, L, mids, to, NUM); else update (T[POS].R, mid + 1, r, to, num );p Ushup (POS);} inline int qsum (int pos, int l, int r, int l, int r) {if (L <= l && R <= R) return t[pos].sm;int mid = (L +  R) >> 1, s = 0;if (L <= mid) S + = Qsum (T[POS].L, L, R, L, mid), if (R > Mid) s + = Qsum (T[POS].R, L, R, Mid + 1, R); return s;} inline int Qmax (int pos, int l, int r, int l, int r) {if (L <= l && R <= R) return t[pos].ma;int mid = (L +  R) >> 1, s = 0;if (L <= mid) s = Qmax (T[POS].L, L, R, L, mid); if (R > Mid) s = max (S, Qmax (T[POS].R, L, R, mid + 1, R)); return s;} inline int Max (int CC, int x, int y) {int ans = 0;while (up[x]! = Up[y]) {if (Deep[up[x] < deep[up[y]]) swap (x, y); ans = max (ans, Qmax (ROOT[CC) , Watch[up[x]], watch[x], 1, N)); x = Fa[up[x]];} if (Deep[x] > Deep[y]) swap (x, y); ans = max (ans, Qmax (ROOT[CC], watch[x], watch[y], 1, N)); return ans;  inline int Sum (int CC, int x, int y) {int ans = 0;while (up[x]! = Up[y]) {if (Deep[up[x]] < Deep[up[y]]) swap (x, y); ans + = Qsum (ROOT[CC], watch[up[x]], watch[x], 1, n); x = Fa[up[x]];} if (Deep[x] > Deep[y]) swap (x, y), ans + = Qsum (ROOT[CC], watch[x], watch[y], 1, n); return ans; int main () {read (n); Read (q), for (int i = 1; I <= n; ++i) read (W[i]), read (C[i]), int u, v;for (int i = 1; i < n; ++i) { Read (u); Read (v); Ins (U, v); Ins (v, u);} _ (1); up[1] = 1;cnt = 0;__ (1), CNT = 0;for (int i = 1; I <= n; ++i) update (Root[c[i]], 1, N, Watch[i], w[i]); Char C; int x, y;for (int i = 1; I <= Q; ++i) {for (c = GetChar (); c < ' A ' | | c > ' Z '; c = GetChar ()); if (c = = ' C ') {c = ge TCHAR (); Read (x); Read (y); if (c = = ' C ') {uPdate (Root[c[x]], 1, N, Watch[x], 0); C[X] = Y;update (Root[c[x], 1, N, Watch[x], w[x]);} else {update (root[c[x]], 1, N, watch[x], y); W[x] = y;}} else {c = GetChar (); Read (x); Read (y), if (c = = ' S ') printf ("%d\n", Sum (C[x], x, y)), elseprintf ("%d\n", Max (C[x], x, y));} return 0;}

Hhhhhhhhhhhhhhhhhh call up to really not easy ah, tree chain split how than $lct$ are difficult to write!!!

$Try $ $Everything $

$ sung: shakira$

Oh oh oh oh oooh

Oh, oh, oh oh.

Oh oh oh oh oooh

Oh, oh, oh oh.

Oh oh oh oh oooh

Oh, oh, oh oh.

Oh oh oh oh oooh

Oh, oh, oh oh.

I messed up tonight I lost another fight

I just screwed up this one, and I didn't get to the end.

I still mess up but I ' ll just start again

Make mistakes but still want to come back

I keep falling down I keep on hitting the ground

Constantly falling down and failing is going to start again

I always get up now-see-what ' s next

Want to touch the heart of the future will always make me stand up and go ahead

Birds don ' t just fly they fall down and get up

The birds that fly in the sky will be hurt, they will break, but they will flutter and fly again.

Nobody learns without getting it won

If you want to get close to the blue sky, you have the courage to fear falling

I won ' t give up no I won ' t give in

I'm not giving up, and I'm not going to let it go

Till I reach the end and then I ll start again

Keep moving forward until I reach my wish and move on to the higher sky

No I won ' t leave I wanna try Everything

I won't run away and I won't hesitate to try life's different

I wanna try even though I could fail

Even if the road ahead is rough, but at least I can feel the scenery after the storm

I won ' t give up no I won ' t give in

I'm not giving up, and I'm not going to let it go

Till I reach the end and then I ll start again

Keep moving forward until I reach my wish and move on to the higher sky

No I won ' t leave I wanna try Everything

I won't run away and I won't hesitate to try life's different

I wanna try even though I could fail

Even if the road ahead is rough, but at least I can feel the scenery after the storm

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

To try to live a different life

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

To experience the scenery after the storm

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

Let the courage to try to write the meaning of life different

Oh oh oh oh oooh

Oh, oh, oh oh.

Look at what far you ' ve come filled your heart with love

When you want to give up, look back and see how many rugged hearts you've been through.

Baby you ' ve done enough that cut your breath

Don't be discouraged, you've done well enough.

Don ' t beat yourself up don ' t need to run so fast

Don't despair, don't be too impatient.

Sometimes we come last but we do our best

Success may come later, but with all your strength, at least you won't regret it.

I won ' t give up no I won ' t give in

I'm not giving up, and I'm not going to let it go

Till I reach the end and then I ll start again

Keep moving forward until I reach my wish and move on to the higher sky

No I won ' t leave I wanna try Everything

I won't run away and I won't hesitate to try life's different

I wanna try even though I could fail

Even if the road ahead is rough, but at least I can feel the scenery after the storm

I won ' t give up no I won ' t give in

I'm not giving up, and I'm not going to let it go

Till I reach the end and then I ll start again

Keep moving forward until I reach my wish and move on to the higher sky

No I won ' t leave I wanna try Everything

I won't run away and I won't hesitate to try life's different

I wanna try even though I could fail

Even if the road ahead is rough, but at least I can feel the scenery after the storm

I ' ll keep on making those new mistakes

I will continue to experience, even if I keep making mistakes.

I ' ll keep on making them every day

Keep trying to make mistakes

Those new mistakes

Keep making mistakes, keep on coming back.

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

Keep trying to keep coming back

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

Constantly experiencing different outcomes in life

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

Continue to experience the continuous progress towards a better self

Oh oh oh oh oooh

Oh, oh, oh oh.

Try everything

Let the courage to try to write on the meaning of life

"Bzoj 3531" "Sdoi 2014" Travel Tree chain split

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.