PengsenMao's blog

By PengsenMao, history, 8 years ago, In English

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 posa now and we wanna go to posb, there are two ways.

1.clockwise, which cost |posa - posb|

2.counter-clockwise, which cost 26 - |posa - posb|

just choose the smaller one.

C++ CODE

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 ai - 1 can be divided by 2

but don't forget ai + 1 shoude decrease 1

why only one? beacause the main idea is to make smaller influence

btw, when ai < 0 ( after decreasing ), stop and exit.

C++ CODE

C. Socks

consider li, ri 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 algorithm.

C++ CODE

D.80-th Level Archeology

imagine we need to sort an array A

we want Ai < Aj  (j > i), we just need to make Ai < Ai + 1

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:AandB(AisinfrontofB)

According to the notice, we know for each i we need Ai ≤ Bi

let x represent the answer, consider two elements, Ai, Bi

if Ai = Bi, skip

if Ai < Bi, absolutely

if Ai > Bi, we also say that

as soon as Ai ≠ Bi is satisfie, we can skip the rest.

how to solve these inequalities? just use Segment_Tree or Bit or Difference

i recommend Difference because C ≤ 106

C++ CODE

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

s[i] represent

do a change, we have

use suffix maximum array is enough.

consider transform as swaping characters.

C++ CODE

F. Video Cards

it is easy to notice that Ai ≤ 2 × 105

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 P = k × Ai, find how many times P appears after modifying

it is easy to solve by the array we created.

because of this is harmonic progression, so it is an algorithm.

C++ CODE

Thanks for reading!

  • Vote: I like it
  • +48
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
Rev. 2   Vote: I like it +2 Vote: I do not like it

if you have questions or some places i am wrong, just point it out to make me improve!

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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?

  • »
    »
    8 years ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    Using terminology of the question , suppose we fix Ai as the leading video card , all secondary cards that we pick must be multiples of Ai i.e P = k * Ai for some k , where P is the secondary card . To find the maximum sum we can get by fixing Ai 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 .

    • »
      »
      »
      8 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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?

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it +2 Vote: I do not like it

        s[a[i]] ++;

        ask how many a[i] appears in [L,R] equal to ask

        prefix sum array can solve it in O(1).

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Would you explain your solution of problem D?

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I am asking the reason for it. It is still not clear to me.

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        let A represent the score of Petya

        B represent the score of the other person

        then

        because the other person also takes the best choice

        so we need

        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.

        • »
          »
          »
          »
          »
          8 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Sorry I misunderstood the problem.. Got it now!

          • »
            »
            »
            »
            »
            »
            8 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            :) in fact i misunderstood the problem at first too.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PengsenMao (previous revision, new revision, compare).