Something need to say
first of all, this is my first tutorial of one whole round, so there must be some places that i need to improve, if you find bug, just comment it and i will be pleasure to update.
Secondly, this round i got rk 151 in div2. it's too stupid that i came up with a wrong idea which made me waste lots of time, but after the competition, i finish them, it seems the offical tutorial still not okay. Therefore, i published this one.
Third, i wanna say thanks to my friends: samzhang[15120] & quailty[quailty]
A. Night at the Museum
We know if we are
Unable to parse markup [type=CF_TEX]
now and we wanna go toUnable to parse markup [type=CF_TEX]
, there are two ways.1.clockwise, which cost
Unable to parse markup [type=CF_TEX]
2.counter-clockwise, which cost
Unable to parse markup [type=CF_TEX]
just choose the smaller one.
B.Coupons and Discounts
there are two ways to buy pizzas:
1.one day, two pizzas.
2.two day, one pizza each day.
We know it is always better if we can buy exactly ai pizzas in that day
but sometimes ai can't be divided by 2
so we need to buy option#2 : one pizza each day
then
Unable to parse markup [type=CF_TEX]
can be divided by 2but don't forget ai + 1 shoude decrease 1
why only one? beacause the main idea is to make smaller influence
btw, when
Unable to parse markup [type=CF_TEX]
( after decreasing ), stop and exit.C. Socks
consider
Unable to parse markup [type=CF_TEX]
as a non-directed edge.so the question changes into: there are some conected components, one component must be the same color, query the minimum times to modify one vector's color.
it's easy to solve with dsu , first of all, we use dsu to get all conected components. For each conected component, we use the color which has the most frequency to colour this connected component.
so we get an
Unable to parse markup [type=CF_TEX]
algorithm.D.80-th Level Archeology
imagine we need to sort an array A
we want
Unable to parse markup [type=CF_TEX]
, we just need to makeUnable to parse markup [type=CF_TEX]
this problem is the same way, if we want all words are sorted, we just need to compare each pair of adjacent words.
consider about the following two words:
Unable to parse markup [type=CF_TEX]
According to the notice, we know for each i we need
Unable to parse markup [type=CF_TEX]
let x represent the answer, consider two elements,
Unable to parse markup [type=CF_TEX]
if
Unable to parse markup [type=CF_TEX]
, skipif
Unable to parse markup [type=CF_TEX]
, absolutelyUnable to parse markup [type=CF_TEX]
if
Unable to parse markup [type=CF_TEX]
, we also say thatUnable to parse markup [type=CF_TEX]
as soon as
Unable to parse markup [type=CF_TEX]
is satisfie, we can skip the rest.how to solve these inequalities? just use Segment_Tree or Bit or Difference
i recommend Difference because
Unable to parse markup [type=CF_TEX]
E. Funny Game
let dp[i] represent the maximum difference when Petya is first,and he got prefix [1, i]
it's easy to see that
Unable to parse markup [type=CF_TEX]
s[i] represent
Unable to parse markup [type=CF_TEX]
do a change, we have
Unable to parse markup [type=CF_TEX]
use suffix maximum array is enough.
consider transform as swaping characters.
F. Video Cards
it is easy to notice that
Unable to parse markup [type=CF_TEX]
so we use an array to count the number of Ai
after that, we suppose Ai is the base
then we know all P that
Unable to parse markup [type=CF_TEX]
, find how many times P appears after modifyingit is easy to solve by the array we created.
because of this is harmonic progression, so it is an algorithm.
Thanks for reading!
if you have questions or some places i am wrong, just point it out to make me improve!
You don't need a segment tree for problem D, just store three segments and update them each time you consider a new pair.
A question considering problem F: "then we know all P that P = k × Ai, find how many times P appears after modifying it is easy to solve by the array we created." What do you mean by this? Could you elaborate further on this statement?
Using terminology of the question , suppose we fix
Unable to parse markup [type=CF_TEX]
as the leading video card , all secondary cards that we pick must be multiples ofUnable to parse markup [type=CF_TEX]
i.eUnable to parse markup [type=CF_TEX]
for some k , where P is the secondary card . To find the maximum sum we can get by fixingUnable to parse markup [type=CF_TEX]
as the leading card , notice that in the original array elements less than Ai can't be picked while all elements > = Ai can be picked . Another observation is that since you can change secondary cards that you pick every number in range [k * Ai, (k + 1) * Ai) would have to be reduced to k * Ai , and count of such numbers can be obtained by maintaining a prefix count array .Thanks, but I still don't get this: "and count of such numbers can be obtained by maintaining a prefix count array ." What do you mean by "such numbers"? How do I use a prefix array to count them?
Ah, I started understanding this. Do we have to sort the initial array in a decreasing order?
s[a[i]] ++;
ask how many a[i] appears in [L,R] equal to ask![](https://espresso.codeforces.com/cf8c6708c257ca0fd335b2d4c6bdd64c668c5f35.png)
prefix sum array can solve it in O(1).
Would you explain your solution of problem D?
which part you don't understand? :)
I do not understand the dp in E. Your dp implies if first person chooses i , then second person will select atleast first i indices. Also how is the effect of new stickers is being taken care of.
that's why we need solve this dp from n to 1.
keep mind that dp[i] represent maximum difference when the first person took [1,i]
so we don't care who is end.
I am asking the reason for it. It is still not clear to me.
let A represent the score of Petya
B represent the score of the other person
then![](https://espresso.codeforces.com/a9414d5ce8e88f1aec04b8265e03f25d1fabe65c.png)
because the other person also takes the best choice
so we need![](https://espresso.codeforces.com/6dea4d2eb653df06db5c132a5781cd7bd219f934.png)
s[i] - dp[j] = s[i] - (A - B) = s[i] - A + B
just like you do a change.
you may ask, then dp[i] represent B not A
but remeber, we've rotated, so it is equal to from B to A.
Sorry I misunderstood the problem.. Got it now!
:) in fact i misunderstood the problem at first too.
Auto comment: topic has been updated by PengsenMao (previous revision, new revision, compare).