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

Автор sajibreadd, история, 5 лет назад, По-английски

We invite you to participate in CodeChef’s April Lunchtime, this Saturday, 25th April, from 7:30 pm to 10:30 pm IST.

3 hours, 5 problems.

We will also be hosting two live problem discussion sessions on Sunday (26th) from 5pm to 6:30pm IST (first 4 problems) and on Monday (27th) from 5pm to 6:30pm IST (last 3 problems), where our panelist, RestingRajarshi will discuss the Lunchtime problems. Find more details here.

Also, if you have some original and engaging problem ideas, and you’re interested in them being used in CodeChef's contests, you can share them here.

Joining me on the problem setting panel are:

  • Setters:Jubayer Alpha_Q Rahman, Shahadat s_h_shahin Hossain Shahin, Md Mahamudur sajibreadd Rahaman Sajib
  • Admin & Tester: Teja teja349 Vardhan Reddy
  • Editorialist: Taranpreet taran_1407 Singh
  • Post-Contest Streaming: Rajarshi RestingRajarshi Basu
  • Statement Verifier: Jakub Xellos Safin
  • Mandarin Translator: Gedi gediiiiiii Zheng
  • Vietnamese Translator: Team VNOI
  • Russian Translator: Fedor Mediocrity Korobeinikov
  • Bengali Translator: Mohammad solaimanope Solaiman
  • Hindi Translator: Akash Shrivastava

Prizes:

Top 10 Indian and top 10 Global school students from ranklist will receive certificates and CodeChef laddus, with which they can claim cool CodeChef goodies. Know more here.

Good luck and have fun!

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

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

sajibreadd , are problems in lunch time sorted according to difficulty or randomly placed ?

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

Problem Statements not loading

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

Problems aren't visible?

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

Problem are not visible.

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

CodeChef always finds ways to suck!

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

Codechef is broken, deeply broken.

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

Where are the problems? xd

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

Problems are not opening .

I reported at [email protected] , hope ,you will resolve it soon.

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

Has anyone actually tried to write to [email protected]? :D

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

At least stop the timer.

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

The problem is... how to find the problem...

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

Lunchtimes on Codechef : —

qqqqqqqqq

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

They are open now

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

Now Problem are visible.

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

Problems visible!

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

Will this contest be rated ???

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

How to solve Positive Mex ?

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

    Sort and store all the numbers with their frequency. Now, if the smallest element of them all is NOT equal to 1, then $$$\displaystyle ans\ =\ 2^{n}$$$ since all the subsequences of this array would have 1 as their mex. Else, for each element check if this element can be made as the mex of some subsequence from our input array. If it can be made, then the contribution it makes to the answer is $$$\displaystyle \ 2^{m}\prod \left( 2^{x_{i}} \ -\ 1\right)$$$ where, x is the count of each number present in the array that is smaller than the current number and m is the count of all all elements greater than this element.

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

It is suspicious regarding "Jumping Fever". Its first subtask is way too easy for no ACs :)

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

What is the intended time complexity for TRIQRY?

My O(N logN) solution TLE's for Java. Even I implemented a custom ArrayList, so ig that shouldn't be the problem.

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

    yes the intended complexity is O(NlogN), i solved it using pbds + offline queries

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

      How did you solve the problem?

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

        A point (xi,yi) will be inside the triangle if xi-yi>=l and xi+yi<=r.(by find the equations of both the lines and then check condition for 2 point to be on one side of a line)

        Now make the pairs of (xi-yi , xi+yi) {or vice versa} , sort them and start from backwards to do offline queries

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

          I am not aware of offline queries yet. Can you please elaborate this statement? "sort them and start from backwards to do offline queries"

          What do we achieve by doing this?

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

            okay so in offline queries we reorder the queries depending on the situation which actually gives some benefits in finding answer of all queries rather than solving queries in the order given in input.

            I dont know any tutorial but i will suggest to try this problem KQUERY. You can google its solution to know how it works

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

    Unfortunately, TreeSet in Java comes with a heavy constant factor. Replacing it with a sorted array would probably help.

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

The problems were very cool, Thanks.

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

Why are constraints so large for TRIQRY? My O(N*logN) solution didn't pass for 100 points. (I know PBDS — indexed set has comparatively greater constant factor but still I see no point in setting such large constraints.)

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

    Yes, at least TL 2.5 secs would have had been fine XD.

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

    Use Fenwick Tree

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

    Yeah, the time limit was quite strict. My code passed after the contest just by changing an int to a bool. Check the difference between non-ac and ac solution: Diff

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

      And mine got accepted just by resubmitting the same code. The time limit should have been more relaxing so that one should not depend on his luck.

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

    From setters perspective there is a point of setting large constraints is to secure the data set. Suppose I have set n <= 10^5, Then if triangles have less than 10^3 points in its region then lot of bruteforce type suboptimal solution will pass and my solution takes .83 sec, So I have set 2 sec TL(twice of it). Yeah I agree with you that 2.5 sec would be cool but using pbds for 10^6 constraints is risky for even 2.5 sec also.

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

Hi all I hope you guys had a nice contest. The editorials for first six problems are ready and would be available in some time.

Posting basic idea for last problem below.

JMPFEVER

EDIT: Solutions

Setter's solution
Tester's solution

EDIT: Slight mistake in original editorial, updated now. I really apologize for inconvenience.

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

    The first 6 editorials are posted.

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

    This problem is quite, quite similar to this one: Link. If I am correct, only changing the line equation by adding the dp value of the current node will be enough. If this is the case, then this problem is just a repeated one.

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

      I have read this problem. This problem just tells to do make prefix sum of path from u to v and in JMPFVR you have to choose all possible way of jumping from u to v. May be solution converts to this problem after doing some stuff like "maximum cost from a node and all of its descendnts" but that doesnt mean it is repeated one.

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

        It's obviously the quite similar. You just have to maintain a dp[u] which will store the best path to all its descendants and add a constant term of dp[u] when adding the line. I don't think it's much different. It would be possible for someone to copy the exact code submitted in the mentioned problem, do small tweaks and submit. The person doesn't have to code the majority of the part, which includes "DSU on tree" and prefix and suffix of its descendants. I think that the implementation was the real reason of no AC submission during contest.

        And one more question, were the solutions rejudged after the contest? I distinctly remember that I submitted the problem just after the contest and got wa after wa even after 14-15 attempts and then gave up. Even the subtasks were not passing. But now I see that all my submissions got ac.

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

        Here is the submission to the cf problem : Link

        Here is the submission to the cc problem : Link

        Here is the difference: Link

        Would you now say that its quite different? Most of the difference is due to the fact that there were multiple test cases in the lunchtime problem.

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

          I have told you that solution might be similar but there should be difference between "repeated one" and "similar solution". Then TRIQUERY should be a repeated one cz I have solved a lot of problems like "how many segments are completely enveloped by a segment" and guess what I dont need to change a single character of my code and I will get ac. So Here the thing that is wanted is different(very different) but thing is they can be found similar way. And I think I don't need to read the codes. I have read that problem and I get your point at that time. If I preprocess dp(u) = max score from node u to all of it's descendents using all possible jumps and pd(u) = max score from all of it's descendnts to u using all possible jumps, then solution is similar. Cz you need to check two cases, pd(u) + direct_jump_score(u,v) + dp(v) and pd(u) + direct_jump_score(u,lca) + direct_jump_score(lca,v) + dp(v) and this problem solves that direct_jump_score(u,v) part so we just need to change m and c of lines. More specifically we need to add dp(u) to c and may be some changes in m(according to my solution). So this can be solved in same way. So " similar solution" and "repeated one" looks different statement to me.

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

            What I am trying to point out is that 90% of the implementation is the same? Had I read the last problem during the contest I would have surely got ac. But had I not solved this problem but knew what was the approach, I wouldn't have been able to solve this during contest. The hard part was the implementation, which could be bypassed. I guess say that it is repeated would not be correct though.

            But what about the rejudging? Why were the submissions rejudged?

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

              May be you would have got ac may be not that's not the issue. This is not repeated one surely but as a contestant perspective solution is similar but I will point out this part direct_jump_score(u, v)(which is recommended in your problem) and max(direct_jump_score(u, a1) + direct_jump_score(a1, a2) + .... + direct_jump_score(am, v))(recommended in my problem) for all possible {a1, a2, a3.....ak} looks very different to me. Yp its rejudged now.

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

              What I am trying to point out is that 90% of the implementation is the same?

              Do you have any idea how many such problems I've solved?

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

I had TLEs on both TRIQRY and HXR because of bad constants. (I used pb_ds on TRIQRY and matrix expo + binary lifting on HXR). Were we expected to use bitsets instead of boolean arrays on HXR? Either way, please increase the time limits next time. I don't see the point of making us try constant factor optimization in-contest.

That said, I enjoyed the problems. Kudos!

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

    I also used arrays instead of bitsets, got TLE, and wasted much time of the contest in optimizing it.

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

    edit: just ignore this, this comment is wrong

    There's apparently a way to do a matrix multiplication in $$$O(n^2)$$$ for HXR (which I don't really understand, but you can look at submissions), so "naive" $$$O(n^3\log{K})$$$ was probably intended to fail the second subtask.

    I agree TRIQRY had too-tight limits. But you could have replaced pbds with a Fenwick tree for a much lighter constant (which I had to do)

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

    Yp, it's expected to use bitset in HXR. For TRIQUERY I have used bit, and we have given 2 times more TL than my solution.

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

Need help in proceeding through different approach of the problem DOTTIME :

My approach : I maintain a segment tree seg[N], where seg[i] represents the sum of all the elements which multiplies to A[i]. (Consider A[i] to be the first element of the product pair)

I proceed to check how A[i] multiplies to the elements from j = 1 to n, by creating an array B[N][N] (Just for bruteforce), where B[i][j] represents how many times A[i] and A[j] multiplies.

I observed that B is symmetric and each row of B is a combination of 4 Arithmetic Progressions. Which first increases from 1 with difference 1 ,then some constant terms , and then decreases to 0.

(This helps me to do 4 range updates in segment tree for each query.)

It was complicated for me to find the indices where these APs start in temrs of i. Can anyone help me with a neat way to find this ??

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

Can someone tell me in TRIQRY, how to find number of points which satisfy x-y>=li and x+y<=ri ?

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

    My Submission.

    Maintain a fenwick tree(BIT) on (x + y). Update it for all points by 1. Maintain the queries in sorted order in terms of l.

    Now for each query from left to right, all the points that have (x — y) before l, cannot be in our answer, and cannot even be for next queries, because queries are sorted in l. So remove these corresponding (x + y) from BIT, by updating these indices by -1.

    Now just get the query(r + 1) from BIT to get the count of the segments which are ending at <= r. By deleting useless segments earlier, yoh have made sure, these segments have x — y >= l as well, and thus the answer follow.

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

Can somebody please provide a test case for which my code fails I tried to do it with segment trees I have already tried many test cases and my code passes for all. It would be great if someone could find a flaw in my solution MY WA solution: https://www.codechef.com/viewsolution/32875190