Блог пользователя GlebsHP

Автор GlebsHP, история, 7 лет назад, По-русски

Всем привет!

Завтрашний раунд пройдёт на наборе задач Московской олимпиады школьников по программированию для 6-9 классов. Пусть вас не смущает возраст участников, московская методическая комиссия постаралась отобрать для олимпиады разнообразные и интересные задачи. Непосредственной разработкой задач занимались feldsherov, ch_egor, halin.george, ipavlov и GlebsHP.

Надеемся увидеть вас завтра в таблице результатов!

P.S. Будет использована стандартная разбалловка.

UPD Поздравляем победителей раунда!

  1. Mr.Stream

  2. mamka

  3. funtik

  4. HE_MATEMATIK

  5. HollowAngel

UPD2 А вот и разбор задач.

  • Проголосовать: нравится
  • +241
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

Auto comment: topic has been translated by GlebsHP (original revision, translated revision, compare)

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится -37 Проголосовать: не нравится

    Этот раунд рейтинговый? Просто в тексте не было информации об этом!

    • »
      »
      »
      7 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

      рейтинговость раунда определяется состоянием системы codeforces)

      the rating you get is the rating than CF just want to give)

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +273 Проголосовать: не нравится

programming competition for school students of grades from 6 to 9.
I was playing Mario when I was in the sixth grade
God bless my childhood

»
7 лет назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

Why is my 3rd hacking attempt still waiting while my 5th attempt has been judged?

»
7 лет назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

Can you change the contest time, please? .. In Egypt we have a weekly prayer time in that time, an hour after that will be perfect.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +100 Проголосовать: не нравится

    The contest time is bounded by the time of onsite competition. It should start after the onsite competition has started and finish before it has finished. I'm sorry, but there is no way we can change the competition time.

»
7 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

I hope to change the time as it time of prayer in most of arabic countries

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

This is the worst timing you can put for arabic muslims :D

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

number of problems ?

»
7 лет назад, # |
  Проголосовать: нравится +29 Проголосовать: не нравится

Seems like the King got resurrected .

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

change the time please. it's our week pray time .

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

will the contest be rated???????

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

These days number of problems <= number of problem setters. Get prepared to read long problem statements and strong pretests. I wish I perform well :)

»
7 лет назад, # |
  Проголосовать: нравится +23 Проголосовать: не нравится

It seems like I am the ONLY arab who will participate in this contest

»
7 лет назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

Canada I am coming.

»
7 лет назад, # |
  Проголосовать: нравится -17 Проголосовать: не нравится

you will notice a decrease of contestants because of the Arabian issue

hope to change the time of the contest

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +71 Проголосовать: не нравится

    Please, keep in mind that Codeforces always tries to vary competitions time to give more people an opportunity to participate in at least some of the contests.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +22 Проголосовать: не нравится

      Exactly. As much as the typical time may work well for arabs, russians and other europeans, the contest usually ends at 2-5am in Korea, Japan, etc. This is a global community and any time chosen would not work for some people. Also it is well explained above why this time cannot be changed as it has to work around the on-site competition.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится

    But when most of competitions carry out in night time for east regions, it's ok for you and you don't have any problems. Think about others sometimes.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +41 Проголосовать: не нравится

This happens when you don't thank MikeMirzayanov, warning! :P

»
7 лет назад, # |
  Проголосовать: нравится -84 Проголосовать: не нравится

To all the people who have pray time during the contest: which one is more important, Codeforces or praying in the name of some god who might or might not exist? I personally think that skipping one day of prayer is justified ;), this can be a secret between you and me, nobody else has to know.

»
7 лет назад, # |
  Проголосовать: нравится +25 Проголосовать: не нравится

Thank God I don't believe in God.

»
7 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Since the king is back, I hope this round will go smoothly :)

»
7 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

I don't like long problem statement , please try to keep it short like atcoder!

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How many to problemset?

»
7 лет назад, # |
  Проголосовать: нравится -45 Проголосовать: не нравится

Can you change the contest time, please? An hour after that will be perfect.

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    Before writing such comments, pls read the previous comments about it! There are only 39+1 comments till now.

    P.S sorry for my poor English :)

»
7 лет назад, # |
  Проголосовать: нравится -27 Проголосовать: не нравится

Is this round will be rated?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Will CF beat the tortoise today?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Will CF beat the tortoise today?

»
7 лет назад, # |
  Проголосовать: нравится +34 Проголосовать: не нравится

Rating prediction for this contest could be found here (after contest begins)

Extensions:

About CF-Predictor

Good luck & high rating for everyone!

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I hope the round will be interesting.Good luck to all participants!

»
7 лет назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

points distribution?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    Come from back and do this : string s = v[i]; while(s > v[i+1])s.pop_back(); v[i] = s; I don't know whether this will pass sys tests

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

    Iterate from (n-1)th string to 1st string, go on comparing with next string and trim this string till it is not greater than the next one.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      But since n can be 5*10^5 and length of string can be 5*10^5,

      won't that solution with its ~ 2.5*10^11 operations be waaaay to slow? (in worst case)

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится -23 Проголосовать: не нравится

Best Div2 Round ever?

»
7 лет назад, # |
  Проголосовать: нравится +54 Проголосовать: не нравится

I think B is harder than D ...

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    If RoyalWyvern above is correct I agree. Had only 13 minutes left after A, B and C. Normally I quit, but I thought what the heck... Past pretests on D... |-)

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится -32 Проголосовать: не нравится

My first comment....Please Upvote me

»
7 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

How to solve E?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Make a set of a,b,h using set < pair<ll,pair<ll,ll> > >
    where first element of pair is b and second is pair(a,h)
    then sort the set.
    Then apply dp a[next_i] < b[i]

    check for the maximum possible height.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    Sort by B values. Then dp[i]=dp[next[i]]+height[i] where next[i] is the nearest ring to the i'th ring such that a[next[i]]<b[i]. Incase no such next[i] exists then dp[i]=height[i].

    Then the answer is the maximum of dp[i] where i varies from 1 to n.

»
7 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

My exact same solution gave me AC in c++ whereas it was giving me TLE in python. This wasted my 15 mins and also 1 incorrect submission

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My correct output is weirdly getting wrong answer on 1st test case itself -_-

Looks like CF knows dark magic to make correct output wrong.

Is D to be solved with trie? I constructed the trie from nth element to first.

»
7 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Why WA in pretest 1 in D? all samples matched... :/

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Same with me.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится -23 Проголосовать: не нравится

    First test may be different from the first example.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится -6 Проголосовать: не нравится

      No it's not. I asked them. In custom invocation also, it's producing wrong answer instead of correct one for sample test case 1. Something's wrong with CF server.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        It might be that CF compiler does not give the same answer for the test as yours.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It may be because the way you outputed the strings. Initially i was changing all the characters that shouldn't be outputed to '\0' and it didn't work,but the next time I just printed the characters I had to and ignored the others(and passed the pretests)

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится -8 Проголосовать: не нравится

      I checked that too. The problem is with server. I ran custom invocation, and my variables are getting incorrectly assigned on CF servers. I had a variable whose value I explicitly set to 0, but CF is taking it to be 1.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +5 Проголосовать: не нравится

        i dont think there is a problem w cf server if it is only your code that is running wrongly. Maybe there is some ambiguity somewhere? why not share your code for us to find out?

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
            Проголосовать: нравится +1 Проголосовать: не нравится

          http://ideone.com/w9V6KY

          Run this code on test case 1.

          My output from custom invocation is this

          output from custom invocation
»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Задача E : Почему мой алгоритм неправильно?

sort honoi by outcome radius non-increasing order.

dp[i] — maximum sum of heights when must use i-th honoi (after sorting) and some j<i honoises.

//there I use segment tree. dp[i] = h[i] + maximum( d[j], 0 <= j < i, and a[j] < b[i] ).

ans = maximum(dp[i], i = 0..n-1);

»
7 лет назад, # |
  Проголосовать: нравится +113 Проголосовать: не нравится

First div 3 round :)

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

i tried to hack a solution using generator but it was showing some return 3 error from validator.exe
Here is the program ,what is wrong in it

generator code

what is wrong with it???

  • »
    »
    7 лет назад, # ^ |
    Rev. 8   Проголосовать: нравится 0 Проголосовать: не нравится

    After sync_with_stdio(false), you cannot mix cout and stdout. Calling fflush(stdout) might be the problem

    EDIT: Nevermind, it seems to be another problem

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      endl automatically does that. Why did he even used that. :P

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      no ,initially fflush was not there, I added fflush when it was showing error

      I feel there are extra spaces at end of rows of input

      Does i care about those extra space?

»
7 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

When you spend all your time solving C and then realize that D was easier(atleast for me) and should have tried that.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

How do you solve C without using bitsets? They make the total complexity of my submission O(k*m/64), and that probably won't pass in 1 second ;( upd: yep, it did not

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I used segment trees with range max query and it passed pretests.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    For each row i calculate min row that can be reached, call it mni. Then if mnr <= l then answer is yes else no.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    p[i] — the first index where an increasing sequence begins, which comes to the i (this sequence can go on). Then check

    if (p[r] <= l) answer is Yes;

  • »
    »
    7 лет назад, # ^ |
    Rev. 6   Проголосовать: нравится +6 Проголосовать: не нравится

    You can store in the array the ranges with the maximum size, that contain sorted column.

    int range[100100]; // range[left] gives right side of the range: int right = range[left]
    
    ...
    
    while (k--)
    {
      int l, r;
      cin >> l >> r;
    
      bool inside = range[l] >= r;
    
      cout << (inside ? "Yes" : "No") << '\n';
    }
    
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      how do you compute range[]? Isn't computing it O(n^2) making it TLE?

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        what I ment was O(n*m) making total running time O(n*m*k) ~ 10^10

      • »
        »
        »
        »
        7 лет назад, # ^ |
        Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

        Look at the example. We can split this matrix into disjoint sorted columns:

        We read this matrix from top to bottom, row by row. When we encounter a value which is smaller than the previous value in that column ( if (val < prev_val[col])) that means we have just met the right end of some sorted range. For example, look at the first column: 1 3 4 5 4. After reading first 4 values 1 3 4 5 we encounter a value 4 which is smaller than the previous value 5. Now when we've found boundaries of the sorted interval 1 3 4 5, we should record them. We know that this interval started at l and we know that it has finished at r. We do a loop for (int i = l; i <= r; i++) and record what we have discovered:

        for (int i = l; i <= r; i++) range[i] = r;
        

        How many times will we touch an element of the matrix? At most 2 times. The first touch happens when we read it. The second touch is when we record the interval with a for loop.

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          Thank you for the amazingly detailed answer.

          I think we can even go bottom-up from n-1 to 0 for each column j, so that every time we descend we remember the largest row index we started descending from and update each a[i][j] accordingly, only needing a single for loop.

          Thanks again!

          • »
            »
            »
            »
            »
            »
            7 лет назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            When we go top down, we don't need to store the original matrix. So top-down traversal should have a smaller memory footprint than bottom-up.

            • »
              »
              »
              »
              »
              »
              »
              7 лет назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

              I understand range[l]>=r but why range[l-1]>=r?

              • »
                »
                »
                »
                »
                »
                »
                »
                7 лет назад, # ^ |
                Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

                I don't know :)
                In the original idea I came up with during the contest I wanted to find 2 intervals which are closest to the given index l. So, I have thought about the following configuration: [l1, r1] l [l2, r2].
                I wanted to check that I fall inside of either the first interval or the second interval.

                But in the algorithm that I have described we need to check only one interval. I will edit my comment.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    I solved it by just traversing the 2d array
    and maintaining a index of minimum and maximum element
    http://codeforces.com/contest/777/submission/24969962

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    You can use Dynamic Programming. You have dp[i][j]-the longest non-decreasing subsegment(continous subarray) of the j-th column that ends in the i-th line.To get it,you simply look in dp[i-1][j] and check if a[i-1][j]<=a[i][j]. If it's true,dp[i][j]=dp[i-1][j]+1,else dp[i][j]=1. Also,you need best[i]=the maximum of dp[i][k] with k in range 1..m At each query,you check if best[r]>=r-l+1 and print the answer depeding on the condition.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    store in one dimension array

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    3 cases: 1) n==1 YES for all requests 2) m<=1000 you can over 1000 colomns all one in O(1) * 100 000=k so it take O(10^8) 3)m>1000 ,so n<= 100 so I just build table answer[100][100] for all possilble l and r

    http://codeforces.com/contest/777/submission/24975294

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is it okay to ask some questions here? I have joined the contest now and also yesterday but I was unable to submit atleast one solution. I wonder why my rating didn't go down yesterday. Will my rating go down now?

»
7 лет назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

KAN please look into what's weird with D? Correct solutions are getting wrong answer!

»
7 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

What was the 4th pretest of E about?

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

    sorting by bi > bj, ai < aj not ai > aj

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      But why the order of a matters? Doesn't the prefix length where we search for the maximum depend only on b? Since any processed aj lesser than b should be ok.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +14 Проголосовать: не нравится

        Yes, it does matter. Unfortunately, I only realized it in the last 2 minutes of the contest. Consider rings with the same b, then we should end the segment with the smallest possible a so that we can use more rings later.

      • »
        »
        »
        »
        7 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

        This order matters because, since a smaller ai can cover many more rings to come, hence, for same 'b', a ring with smaller 'a' should come later, so that it adds up to a greater dp value. Otherwise, your answer can be lesser than it should be.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Thank you!

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Couldn't figure it out till the end,was checking my segtree implementation for every WA. Anyways, it was easy but good problem.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

When you about to click submit button for D and the contest ends. Hope my solution was wrong.

»
7 лет назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

With some Arabs praying and some other people sleeping or working Codeforces was deliciously responsive today! Thanks!

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

The test should be at most 256 kb .

Then how can i hack o(n*m*k) solutions at C or o(n*l) solutions at D?

»
7 лет назад, # |
  Проголосовать: нравится +32 Проголосовать: не нравится

Looks like the Div.2 rank.1's solution was written by multiple people.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +22 Проголосовать: не нравится

    ha ha... 5 codes and 4 different templates :p They could've atleast used the same template.

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Очень хороший раунд, задачки на логику.

»
7 лет назад, # |
  Проголосовать: нравится -42 Проголосовать: не нравится

My request to feldsherov, ch_egor, halin.george, ipavlov, GlebsHP and KAN

Please look into D. Something's wrong with CF server!

Here's proof

http://codeforces.com/contest/777/submission/24975275

http://ideone.com/Mxgyyt -> exactly same node, not even a character has been changed. You can compare diff if you want.

Results are so different!

I don't want to lose points because server's fault. Please look into it!

Thanks!

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    It's not server's fault. You have UB somewhere.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +20 Проголосовать: не нравится

    You are blue, but u talk like a complete newbie. By now, you should know that compiler versions differ on different Online platforms, and thus produce different outputs.

    Don't u feel like taking a second off and thinking about what may have gone wrong before blaming the CF server and taging all admins ?

    This is sheer stupidity, and complete newbie attitude. How many times have we seen this same query from multiple multiple people ?

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится -17 Проголосовать: не нравится

      I challenge you to find a UB in my code! If you do, then you can call me newbie :) Deal?

      If you can't find bug, then you by default admit I am right, and I should get my ratings back.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +15 Проголосовать: не нравится

    You used the memory returned by malloc without initializing it, which may behave differently by environments.

»
7 лет назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

Anyone else solved E with sorting and a stack? I can explain my solution if there is interest.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Really? How? I used segment tree + heap, but I'm pretty sure BIT can be used instead of segment tree.

    • »
      »
      »
      7 лет назад, # ^ |
      Rev. 3   Проголосовать: нравится +11 Проголосовать: не нравится

      Well, here's a description of my solution:

      First, you sort the disks in a descending order, prioritizing the variables in the order b, a, h. (Note: my code actually swaps the names of a and b) Then, you go through the disks in the sorted order. You remove as many disks as you need to from the stack, until you can place the currently processed disk on top. You maintain the current total height of the stack, and also a maximum achieved height. The maximum height is the answer.

      I couldn't come up with a proof for this, but neither could I come up with any counter-example, and it surpassed all the tests. It just felt like it could work.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I also have no idea why that works :)

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится -11 Проголосовать: не нравится

        I was 30 minutes late to the round. I solved from a fake id. I did this way :)
        This is not cheating :P I didn't submit from multiple id's :P

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I am sorting according to outer radius (bigger outer radius first).If outer radius is equal ,then sort by inner radius (again bigger inner radius first ) . Now let's say I have kept two data in my stack for every element (the inner radius and the height) . I maintain a global height variable 'gh'. What I do in every step is that I pop the stack elements till I get the top of stack element whose inner radius is lesser than the current element's outer radius.And then I come out of the loop and push the current element on the stack. In every push and pop operation I update the global height variable gh. And in every iteration of loop I update the final answer.

        Why this would work ? Everytime one pops an element whose inner radius is greater or equal to the current element's outer radius , it's guaranteed that the popped element can't be used in the future as we have already sorted by outer radius so the element's coming later on also won't fit on top of this ring.

        Complexity : NlogN for sorting and N for the main loop with stack operations.

        My solution

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    same here :)

»
7 лет назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится

Этот раунд самый удачный — 777

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

The first time I have solved 4 problems.

»
7 лет назад, # |
  Проголосовать: нравится +35 Проголосовать: не нравится

My skill is like Petr's or tourist's when they were in 6th grade.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

A: AC

B: FST (WA)

C: FST (TLE)

What happened to my brain?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to solve E with segment tree?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Compress the inner and outer radiuses so that all radiuses are less than 200000.

    Sort all the rings by outer radius in the decreasing order. In the case of a tie, sort them by the inner radius, also in the decreasing order.

    For each ring, calculate the maximum height of a tower with that ring on top. This is obviously the height of the ring + maximum height of towers where the top ring has inner radius less than the outer radius of the current ring. Solution with segment tree becomes obvious now.

»
7 лет назад, # |
  Проголосовать: нравится +27 Проголосовать: не нравится

I am shocked by the programs of THE RK1. I don't think a people will code in more than FOUR different code styles. I don't mean he has cheated,just curious.

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +38 Проголосовать: не нравится

I know a little about the rank 1[user:Mr.Stream] but I know he is about 60 years old. What an unbelievable achievement!!! Could i make friends with you? Thx!

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится

    you will make friends with 4 people QwQ

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Although the rank 1 is used the name of XianYou Xu,but I guess he is not the 60 years old man,maybe it is just a joke by his student.

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

I'm too stupid.I use memset and strlen() in the for loop.And I got TLE in C and D

»
7 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Contest was easier than usual, D was little easier than C.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

About the Rank 1...

There was a legendary man called HangZhou Blade Master...

and now you see that...

»
7 лет назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Actually i can't why My E Programme TLE ON 13..... And i want to say congratulation to rk1[Mr.stream]

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

D is the worst question, why is it D, I think A is harder than D, liked solving C. Why is it like that.

»
7 лет назад, # |
  Проголосовать: нравится +22 Проголосовать: не нравится

A shoutout to all those who stumbled at pretest #4 in problem E cuz of the sort :D

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

When can we see the solutions?

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

Could anyone please tell me why my solution on E got a Wrong Answer on test 39? I tried to solve it by using set and multiset instead of a segment tree,but it failed. Is it possible to solve E this way?Thank you! Here is my solution : http://codeforces.com/contest/777/submission/24972634

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    I came up with a group of input to prove my code incorrect. And I found the elements I intended to put into the set actually failed to be inserted. Can anybody tell me why?

    Here is the data:

    5

    2 3 1

    2 4 1

    2 5 1

    2 8 1

    1 2 1

    The expected answer is 4,but I got the incorrect answer 5.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Some interesting bug I discover. So my submission 24970450 got wrong answer on pretest one. But when I run it on custom invocation, I got the same answer.

#b

#big

#big

Whereas the output from the judge is

#b??

#big

#big

I know the error comes from my failure in resizing the string, but shouldn't the custom invocation gives the same output as the judge?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I guess, that "??" is just to show, that there are space characters. In custom invocation there are 2 spaces instead of "??"

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      but why does whitespace matter when u print? i can always print excess whitespace at the end of the line and still get AC

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    '\0' and ' ' are different.........

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      that should make my code even more correct. cause cout will automatically ignore everything after '\0'...

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        char[] and string are different. string won't ignore '\0'.It records the length directly.

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          read link

          It says there "This function overloads operator<< to behave as described in ostream::operator<< for c-strings, but applied to string objects."

          If you dont believe me, try writing something like:

          string str = "Chestnut\0Zun";
          cout<<str<<endl;
          

          the result would be just Chestnut.

          • »
            »
            »
            »
            »
            »
            7 лет назад, # ^ |
            Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

            char[] ends with '\0',so when you convert char[] to string,it will only convert chars before '\0'.

            You can try this

            string str = "Chestnut-Zun";
            str[8]='\0';
            cout<<str<<endl;
            
            • »
              »
              »
              »
              »
              »
              »
              7 лет назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

              ok, looks like i am wrong then. This is indeed interesting, I got ChestnutZun when I print to my terminal(which looks like '\0' being ignored) but I got 4368 6573 746e 7574 005a 756e 0a when I print to a file. Do you have any idea why?

              • »
                »
                »
                »
                »
                »
                »
                »
                7 лет назад, # ^ |
                  Проголосовать: нравится 0 Проголосовать: не нравится

                Maybe '\0' was ignored by your terminal.It looks like a space on mine(Windows cmd).

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 лет назад, # ^ |
                    Проголосовать: нравится 0 Проголосовать: не нравится

                  i run it on my terminal, cf and ideone though.all of them ignored '\0'

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 лет назад, # ^ |
                    Проголосовать: нравится 0 Проголосовать: не нравится

                  most of browsers ignore it too..... Custom invocation and online ide don't escape '\0',but submissions page do....

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 лет назад, # ^ |
                    Проголосовать: нравится 0 Проголосовать: не нравится

                  oh ok, thanks.

»
7 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Is it possible to use fenwick tree instead of segment tree for problem E? I'm got AC with segment tree but WA with fenwick. However, I've used fenwick on prefix RMQ problems before (i.e. when we query for prefixes only) and they've all passed. So now I'm wondering if it's possible or not?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится
    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Maybe this is a stupid question, but why was it necessary to group a and b into the same array and operate fenwick on that array? Wouldn't it be correct to update on the indices of the given array from input?

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        The values are large enough and distributed randomly, so maybe this is a stupid question, but how can we use indices instead of real values?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain me the complexity analysis of my solution to problem C. Submission Link

My approach was to store all the increasing sequences in in each column ans push the starting and ending points int the map, along with size of sequences and the column in which it occurs. I also store the length of increasing sequences in "pts" vector. This vector is then sorted and duplicates removed from it. Now, for a given query, I simply iterate for all possible length >= (r-l+1) and check if I can get an answer from it. For a given "j", the answer exists only when the pre-computed range covers the entire length. This can be broken down into 3 cases (Similar to linear inequalities). If answer is found at any point of time, I stop the process else I brute force for all possible values of "j" and all possible positions in the matrix.

I think this solution of mine can give TLE on some cases where number of answers "NO" is very large. But even I was not able to come up with a test case where my solution fails. (I have tried this technique in few questions earlier too, but never failed). But still can anyone help me in analysing the complexity of my solution. ?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yeah, This does seem like it should have TLE'd. Since your query answering time can possibly be linear. So your complexity should be n*m*Log(n*m) + n*m*k

    Former is for the preprocessing on finding non decreasing sequences, while latter is for query answering. As for each of the K queries, in the worse case you might have to iterate through all of the n*m (max possible number of sequences) to find your answer.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Now, I feel the complexity analysis can go as follows. The are sqrt distinct values below given N. So, in most cases, it perform query in O(sqrt(n)). But there is one particular case where it will TLE. The case is as follows. All the columns should be strictly decreasing. So cnt in this case is 1 everywhere. Now, if each query is (n, n), then k in my case will be 1 and I will have to iterate through each of the (n-1)*m grid points to tell the solution.

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I don't get how you got sqrt distinct values ? sqrt(n) distinct values of what ?

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          Number of distinct values in "pts" vector.

          • »
            »
            »
            »
            »
            »
            7 лет назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            Only iterating distinct values >=(r-l+1) isn't gonna get you the answer right ? You need to know the starting point too. So in the worse case it is still n*m*k right?

            Even if for each distinct size length the list of starting indices is sorted so you can binary search for the query start. It still adds another Log factor to the sqrt, which shouldn't pass the time limit.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

There has been some time since a saw sneaky pretests like these. They were all really light weighted and I forgot how painful it's to discover it after the contest is over.

Yesterday I was Specialist, today I'm sad.

=(

»
7 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

What's about announcing the winners of the contest?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It's annoying when you are in Top 5 of Div. 1 participants, but author announced only winners from Div. 2.

»
7 лет назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

Waiting for the editorial! Someone please tell me how to do problem C??

  • »
    »
    7 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится +5 Проголосовать: не нравится

    My solution solves the queries offline.

    For each row x find the minimum row i, such that the interval [i..x] on some coloumn is non-decreasing.Then iterate through all the queries which end in x and if i < q[x].l , then the answer for the query q[x].order is "Yes" , else it's "No".Thus the complexity is O(n * m + k).

    Check my code for better understanding.

»
7 лет назад, # |
Rev. 3   Проголосовать: нравится -16 Проголосовать: не нравится

About problem E. Many people thought why greedy solution works. The answer is simple: tests are weak.

I wrote my greedy by sorting on bi in non increasing order and ai in non decreasing and failed pretest 4. Then I changed the order on ai to be non increasing too and it passed. I was angry that I did not notice that during the contest. Here is the submission: http://codeforces.com/contest/777/submission/24979922

I did not notice that property, as it does not work. Here is the counter example, where sorting by ai in non decreasing order gives a better result:

2
2 2 3
1 2 3

The answer is 6, but my program returns 3. It is a pity that these tests were so weak and so many incorrect solutions to the hardest task were accepted.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    This is an invalid input because bi must be greater than ai.

    • »
      »
      »
      7 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

      Right. In that case greedy works as you would be always able to cover all coverable ai, with bj.

      Edit. How to solve the task with ai <= bi?

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        Note that if we place some ai = bi ring, we cannot stack any rings more on it (contradiction: bi >= b_(i+1) > ai = bi) So first we solve the problem with ai < bi rings, and process ai = bi rings later.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I think Greedy Works always :)
    I faced a nearly same problem as you
    24985372 WA on test #22.. Using >= in sorting.
    24985387 AC only removing that = sign :(

    But I don't know why... Shouldn't I sort in Non-Increasing Order?

»
7 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

А разбор будет?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My solution for problem E gave WA, but I can not understand what I did wrong. Here is my approach:

  1. Sort the rings with respect to 'b' in descending order.

  2. Now consider the rings in the sorted order.

  3. For the ith ring, get the maximum height achieved by i-1 rings with 'a' less than 'b' of the ith ring (used coordinate compression and segment tree for this).

  4. Add the above height to the height of the ith ring and store this value for the ith ring.

  5. Maximum achieved height by all rings after all of them have been processed is the answer.

Link to the solution : http://codeforces.com/contest/777/submission/24974400

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Разбор этих задач вообще будет?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Nice problemset good work man!!

»
7 лет назад, # |
Rev. 10   Проголосовать: нравится 0 Проголосовать: не нравится

UPDATE: Sorry...wrong thread...it should be under round 402

http://codeforces.com/blog/entry/50658?#comment-346176