Can anybody post their solution to problem G?
Can anybody post their solution to problem G?
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 162 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
9 | pajenegod | 145 |
9 | SecondThread | 145 |
Name |
---|
Neither I, nor my teammates could solve it:(
How to solve A, H?
H: Let's say
Unable to parse markup [type=CF_MATHJAX]
Call the frequency sequence of $$$a$$$ to be the sequence $$$f$$$, where $$$f_i$$$ is the frequency of $$$i$$$ in $$$a$$$. We'll prove that for some frequency sequence $$$f$$$ with all values < $$$q$$$, the sum of $$$g(a)$$$ over all permutations $$$a$$$ with frequency sequence $$$f$$$ is $$$0$$$ and hence, it is enough to just consider arrays with all values same to solve the problem.
To find the sum, we can consider all values different and divide by
Unable to parse markup [type=CF_MATHJAX]
.Unable to parse markup [type=CF_MATHJAX]
=Unable to parse markup [type=CF_MATHJAX]
=
Unable to parse markup [type=CF_MATHJAX]
=
Unable to parse markup [type=CF_MATHJAX]
, where $$$F_i$$$ is sum of $$$a$$$ taken $$$i$$$ at a time.Now, we can iterate on $$$|S|$$$. And our sum becomes:
Unable to parse markup [type=CF_MATHJAX]
The final summand is sum taken $$$k$$$ at a time from
Unable to parse markup [type=CF_MATHJAX]
, which is non-zero only for $$$k=0$$$ andUnable to parse markup [type=CF_MATHJAX]
, asUnable to parse markup [type=CF_MATHJAX]
.So, our sum becomes
Unable to parse markup [type=CF_MATHJAX]
= sum of the array $$$a$$$.Also,
Unable to parse markup [type=CF_MATHJAX]
So, the total sum becomes $$$0$$$ for any $$$f$$$ with all values < $$$q$$$.
It actually suffices to consider only the cyclic rotations of a particular string, rather than all permutations. Consider the polynomial $$$P(x) = \displaystyle\prod_{i=1}^{q} (a_i + i + x)$$$. Then, summed over cyclic rotations of the string, the first term is $$$\sum_{x=0}^{q-1} P(x)$$$. Now,
$$$P(x)$$$ has degree $$$q$$$, so for $$$q > 2$$$, only the $$$x^{q-1}$$$ term has nonzero value. In particular, the value of the sum is $$$(q-1) \sum_{i=1}^{q} a_i + i = (q-1) \sum_{i=1}^{q} a_i$$$. The rest of the proof is essentially the same.
(For $$$q=2$$$, we can directly analyze $$$g(ab)$$$ versus $$$g(ba)$$$.)
Problem G goes like that:
It's easy to see if a subseq&=0, in every bit there will be a number equaling to 0.
we used inclusion-exclusion principle. Let $$$f_x$$$ be the number of $$$a_i$$$ that includes bitset $$$x$$$, which is easy to get with FMT.
The answer for $$$i$$$ is
Unable to parse markup [type=CF_MATHJAX]
, with FFT we can calculate it in $$$O(n\log n)$$$.By the way, How to solve H and J?
J: We can find the expected value of max(0, bacteria inside — bacteria outside) for one petri-dish and multiply by $$$n$$$.
Let $$$x$$$ be the bacteria inside and $$$y$$$ outside. We have a simple process. We go from
Unable to parse markup [type=CF_MATHJAX]
with probabilityUnable to parse markup [type=CF_MATHJAX]
andUnable to parse markup [type=CF_MATHJAX]
with probabilityUnable to parse markup [type=CF_MATHJAX]
.Initially we have
Unable to parse markup [type=CF_MATHJAX]
. Say in $$$r$$$ minutes $$$a$$$ bacteria were added inside andUnable to parse markup [type=CF_MATHJAX]
outside. The probability of this happening is:Unable to parse markup [type=CF_MATHJAX]
.So, the value after $$$r$$$ minutes is
Unable to parse markup [type=CF_MATHJAX]
.We can store prefix sums of
Unable to parse markup [type=CF_MATHJAX]
andUnable to parse markup [type=CF_MATHJAX]
(or use hockey stick identity) to find the answer for each $$$r$$$ in $$$O(1)$$$UPD: Sorry I didn't realize that jtnydv25 had posted the solution above :(
H: The main observation is if the multiset of the digits
Unable to parse markup [type=CF_MATHJAX]
contains two different numbers, the sum of luckiness over all permutations of these digits will be equal to zero. So you only need to take all numbers with equal digits and add them to the answer. In the contest, I simply guessed the conclusion and used a brute force solution to verify it.Proof: Note that
Unable to parse markup [type=CF_MATHJAX]
, where $$$f(A)$$$ equals to the number of the permutations of the multiset $$$A$$$ (i.e.Unable to parse markup [type=CF_MATHJAX]
). Since $$$q$$$ is prime, the polynomialUnable to parse markup [type=CF_MATHJAX]
, so we haveUnable to parse markup [type=CF_MATHJAX]
. For the first term,Unable to parse markup [type=CF_MATHJAX]
since the $$$S$$$ contains at least two different numbers. For the second term, note thatUnable to parse markup [type=CF_MATHJAX]
, so the overall sum equals to $$$0$$$.By the way, I don't think this task is suitable for a contest. It's more like a work based on the existing proof, and I didn't do anything in the contest except guess the conclusion...
and how to do that with fft?
Let
Unable to parse markup [type=CF_MATHJAX]
andUnable to parse markup [type=CF_MATHJAX]
. This gives usUnable to parse markup [type=CF_MATHJAX]
.Using sequences
Unable to parse markup [type=CF_MATHJAX]
andUnable to parse markup [type=CF_MATHJAX]
, we haveUnable to parse markup [type=CF_MATHJAX]
(Intuitively,
Unable to parse markup [type=CF_MATHJAX]
multiplied by $$$x^N$$$ gives the polynomial $$$B$$$.)Is there any simple way to solve A?
My ugly approach is to use a union-find structure to maintain the current component of ants, and the whole process needs a linked list or something similar to compress the vertices of degree $$$2$$$. But it contains so many corner cases and details that it's a nightmare to implement it.
You can use the same approach but with sqrt decomposition on queries. It becomes relatively easy to implement.
It was quite confusing that two of us knew that in problem J it suffices to find a matching which maximizes sum of squares of edge lengths. In the end we came up with some solution finding a good cross composed of two lines in
Unable to parse markup [type=CF_MATHJAX]
, but we were kinda trying to finish other problems.