Комментарии
На MrPupsikOrz Chat Is Here! (Finally), 9 месяцев назад
-8

orz

На i_love_sqrt_decompWhat's the fastest DS?, 9 месяцев назад
+3

Bro, note that $$$Q\le 2\times10^7$$$

На ServalCodeforces Round #853 (Div. 2) Editorial, 3 года назад
0

I think the tutorials means that those intervals are illegal.

An interval is illegal means that if $$$s_i\in[l, r]$$$, $$$i$$$ will not be counted into $$$f(x)$$$.

На chen_yi_bingCSP RP++, 4 года назад
+4

3q

На AkulyatCodeforces Round #824 — editorial, 4 года назад
0

[deleted]

На AkulyatCodeforces Round #824 — editorial, 4 года назад
0

[deleted]

Thanks, dude!

It's so sad for me since I cannnot solve some easy problems recently. As you can see, my rating and rank dropped during some previous contest. I'm also looking for some solutions. :(

I don't think this solution should be hacked. At least it showed an important way to improve the time complexity($$$O(\frac{1}{\omega})$$$). In my point of view, various solutions are also important and inspiring.

Though my rating dropped after the contest, I think it's a pretty good round.

Because it made me realize my poor ability in dp on tree :)

На KeshiCodeforces Round #800 Editorial, 4 года назад
+3

Could you plz explain why starting from 1 will get WA, while starting from n can find out the correct answer? I didn't get that :(

Actually, I made some testcases that can hack my program(starting from 1). But I don't know why it can be correct to start from n.

На AmShZCodeforces Round #800, 4 года назад
+50

It should be [1900, tourist].

I agree with you.

btw, it's common in China. LOL

На huangziruiCodeforces Round #796, 4 года назад
0

Pardon?

На awooEducational Codeforces Round 129 Editorial, 4 года назад
0

Yeah, thank you, very clear.

На awooEducational Codeforces Round 129 Editorial, 4 года назад
+6

Sorry for the late reply and my poor English.

Let's try to calculate the answer from the different weights.

For every kind of weight of an edge, try to figure out the value that this kind of edge contributes to the answer.

For example, in the following illustration, the contribution of edges weigh $$$2$$$ is $$$3\times1+3\times3=10$$$.

illustration_1

Why?

If we cut the every edge weighs $$$2$$$(red edges), we will get $$$3$$$ new trees.

For the edge $$$(6, 7)$$$, the new trees it connected are $$$4,5,6$$$ and $$$7$$$, so answer will add $$$1\times3$$$. Because for the paths from $$$u$$$ to $$$v$$$, where $$$u=4,5,6$$$ and $$$v=7$$$, the value $$$2$$$ will definitly appear exactly once.

For the same reason, edge $$$(4, 1)$$$ will contribute $$$3\times 3$$$ to the answer.

Obviously, the edges with different values can't influence each other, so You can calculate the different values of edges partly.

Here is how to calculate the answer of edges with same value.

Firstly, get the 'bracket order' of the tree. Let $$$L[u]$$$ and $$$R[u]$$$ be the begining and ending indices of $$$u$$$ in the 'bracket order'.

It's another kind of Euler Tour of Tree. Instead of output the number as soon as you visit a node, you will output the number only when you first visit the node or finish visiting the node.

I don't know how to translate 'bracket order' to English since I'm Chinese and my English is poor. For example, the 'bracket order' of the tree in the illustration is $$$\texttt{4 5 5 6 7 7 6 1 2 2 3 3 1 4}$$$, hope you can understand what I want to express from the example. Or maybe you can see my code in the end.

Then, for a tree, cut the edges in dfs order and split the subtrees out, and cut the edges in a subtree recursively.

function Cut(int CurL, int CurR, int &CurE):
    for CurE in [CurL, CurR]:
        cur_real_size -= size[v]
        append value of Cut(L[v], R[v], CurE) to real_subtree_size
    for val in real_subtree_size:
        answer += val * cur_real_size
    return cur_real_size
// edges are sorted in dfs order, so an edge have a dfs order, you can judge whether the edge is in the subtree or not.
// CurE means the index of the edge you are visiting

When you cut the subtree recursively and update CurE, CurE is increasing and always less than $$$O(n)$$$. So the time complexity is $$$O(n)$$$.

You can see my submission to have a better understanding, I think it's quite short: 158222894

Actually I don't know whether it's violation of rules for me to type the solution in the comment. If it is, please tell me and I will delete my comment at once.

Apologise again for my poor English.

На awooEducational Codeforces Round 129 Editorial, 4 года назад
0

If you like, I can give another solution to you.

But it solves the problem from an aspect differ from the tutorial.

0

congratulations

0

I think your graph is so inspiring, too.

If someone is going to be an expert, it must be you. XD

На rivalqCodeforces Round #793 (Div. 2) Editorial, 4 года назад
0

lol

На rivalqCodeforces Round #793 (Div. 2) Editorial, 4 года назад
0

got it, thx

На rivalqCodeforces Round #793 (Div. 2) Editorial, 4 года назад
0

But it seems that the number of edges is $$$O(n^2)$$$..?

На rivalqCodeforces Round #793 (Div. 2) Editorial, 4 года назад
0

Awesome! Thank you very much

На rivalqCodeforces Round #793 (Div. 2) Editorial, 4 года назад
0

I only have an $$$O(n^2)$$$ algorithm. For each loop, choose one node as the starting point, then judge whether the dfs order on the tree is same as the loop's order.

На rivalqCodeforces Round #793 (Div. 2) Editorial, 4 года назад
0

Yes, but I have no idea how to solve it on the tree