Автор awoo, история, 5 месяцев назад, По-русски

Привет, Codeforces!

В 03.12.2023 17:35 (Московское время) состоится Educational Codeforces Round 159 (Rated for Div. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Иван BledDest Андросов, Максим Neon Мещеряков и Роман Roms Глазов. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

UPD: Разбор опубликован

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

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

1st comment :>

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

Hope this round to be fun :P

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

.

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

Hope to get back to expert after this round! GL everyone :)

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

Hope that it'll be an amazing contest!

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

What's the rating distribution for problems

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

Good luck everyone and have fun ^_^

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

Educational Rounds are Mathforces af. Gonna skip this one

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

My semester final exam in 4th December and 6th December and so on... But, I surely participate this Round also the upcoming div 3.

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

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

Inshaallah, In this round I will be Green.

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

hope it will be fun

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

Educational rounds always offer so much to learn... Hope to solve D today in contest..

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

Hoping to become a pupil after this round

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

Решения будут доступны потом, чтобы посмотреть, как решать надо было?

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

hope to get back to pupil after this round

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

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

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

After 127 contests and I'm still a NEWBIE gonna set a world record :(

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

i hope to reach pupil.

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

D >> C

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

    But E < D imo, so always be sure to read at least one more problem than the one you're stuck on.

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

Speedforces

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

Can anyone show me the formula to solve the problem B please? For me problem C is easier :D

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

    you can do binary search instead of coming up a formula directly :D

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

      I can't see the idea to do binary search. Can you help me?

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

        well you got to do is find the greedy function check(x) which checks if x is valid solution and then do classic binary search whicch find the smallest x such that check(x) is true.i am not so sure because i came up with a formula during the contest

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

        you can binary search the minimum amount of days that Monocarp cannot rest, let's say $$$mid$$$ days, then Monocarp can earn $$$mid*l+\min(2*mid,c)*t$$$ points, where $$$c=\lfloor (n+6)/7 \rfloor$$$ is the number of tasks unlocked within $$$n$$$ days.

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

          I think it should be c = [(mid+6)/7] (correct me if I'm wrong)

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

            It has to be with $$$n$$$, because maximum number of tasks that you can do is always the same and equals to $$$⌊(n+6)/7⌋$$$.

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

    For me B was trivial not C :((

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

    there are 3 thing you can do in a day

    1. attending a lesson
    2. attending a lesson + one task
    3. attending a lesson + two task

    we have ((day -1) / 7 + 1) tasks unlocked.

    so we will do 3. for tasks/2 days

    then do 2. if tasks is odd

    then 1. for remaining point

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

    Binary search is probably an easier method, but I found a formula, so here it is:

    Note that I'm pretty sure this constant-time solution is slower than binary search lmao.

    235560283

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

      How can you justify the claim you made in the first para, I could attend more lectures and do. no practical I can get potential 14*l every 2 weeks, instead of l+2t, we don't know any relation between l and t so how can you say that that is the optimal, maybe the testcases are such that t is large enough to make it optimal

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

        You have to minimize the number of days but if you are completing all the lectures then you are not minimizing. It would be better to consider first all possible l+2t and then the residue points should be used against the number of extra days where we will only attend lectures.

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

        By 'most efficient' I meant optimizing for time spent studying, not time passing. In other words, there is no way to earn more than l + 2t points in a single day, and these days cannot be done more often than once every 2 weeks.

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

    this is my submission, i used math not binary search.

    https://codeforces.com/contest/1902/submission/235665532

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

Problem D is difficult to implement.

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

Problem F is first known as "[SCOI2016] 幸运数字", a problem from 7 years ago

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

For F, why using xor basis gives me WA on test 54?

https://codeforces.com/contest/1902/submission/235578100

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

I might have just clutched problem D

Great success?
»
5 месяцев назад, # |
  Проголосовать: нравится -17 Проголосовать: не нравится

D >> E,F

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

4 submissions on B :)

Also E < D.

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

If anyone solved E using string hashing, drop the solution here

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

:( +1 penalty in C because the constraint 'x is a positive integer' got updated after I opened the link. Also, no idea why directly solving the inequality in B gives WA but a binary search approach passes.

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

Cluthed D with 2 mins left !!

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

me getting +3 on B but 0 on C didn't include a '()' if you see my submission :(

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

Why E with such tight constraints on ML with trie, was it not intended? Saw many hashing solutions passing instead, made me sad ;(

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

after this contest i dont hate anything more than math

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

Failed D just because I forgot to check whether set.lower_bound(l) was equal to set.end(). Submitted the moment submissions opened and got AC. Good thing it was "out of competition".

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

Looking into my time spent to solve each problem, the most difficult one from A to E was problem B.

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

after this round i dont hate anything more than math

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

First time solved F during contest and finished debugging E 1 sec after contest was over.

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

I fucking missed $$$D$$$ just by a few seconds , bro!!!

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

Whats the idea behind E?

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

    I built a trie of all strings where each node further keeps track of the number of strings in the subtrie, as well as the total length of the strings in the subtrie while excluding the common prefix that the node represents.

    Then for each string, I read the characters in reverse-order and traverse the trie, with each step denoting a collapse step, while carefully accumulating the contributions to the desired sum of the other branches (concatenation cases) by utilizing the stored values.

    My submission: 235592382 I used a 2D array for the trie, which was probably a terrible idea (almost broke the memory limit), but the logic should be sound. I can elaborate on the details further if you want.

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

I think problem D should give more time, I am sure I use a right O(nlogn) algorithm and implement it in python, however it's always show "tle". 2000ms is too short for D!

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

Please why is my submission for F WA on test 9

My thought is divide and conquer with XOR-basis with $$$q\log^2A$$$ complexity

code for F

thanks very much!!

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

Am I the only fool who spent 1 hour and a half to figure out the solution for C while solved E in merely 15 minutes...

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

    I'm the fool who couldn't solve E in 1 hour 40 minutes yet solved C in the first 11 minutes.

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

In problem D, does the reversed commands range represent the same path, but mirrored around some line parallel to y = x?

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

    Nope. Well, it might always be mirrored around some line, but that line definitely isn't necessarily parallel to y = x. For example, if you keep going up, then reversing does nothing, and your mirror line is a vertical line, and similarly, going right only yields a horizontal mirror line.

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

      I think it should be mirrored around some dot, but I don't think that's somehow necessary for solution

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

      Hmmm... Is it the line from the start of path to its end? If so, we can always just find it and mirror given point to check if it is within given range.

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

        Nope, that's not it either. For example, if you move in a square wave, e.g., URDRURDRURDR..., the mirror line is a vertical line in the middle, which doesn't contain the start or the end.

        If there is some geometry-based solution to solve this problem, it would likely be much harder than simply precomputing the forward and reverse paths separately (which is likely the intended approach), so I wouldn't recommend thinking too hard about these geometric properties.

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

    Nope

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

    I might be wrong with that thinking, but my base idea is that after flipping, the prefix and suffix of points remains unchanged. If so, we can somehow transform given point and check if it is within prefix, suffix, and given range.

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

    You're on the right track. Let $$$p_i$$$ be the point we're on before executing the $$$i^{th}$$$ command. Now to reverse a segment $$$[l, r]$$$ of the path, shift the origin to $$$p_{r+1}$$$ and mirror all the points on this segment around $$$x=-y$$$, (the transform is $$$(x,y)\to(-x,-y)$$$). Then, shift the origin to $$$p_l$$$. If we treat the points as vectors, then the point before the $$$i^{th}$$$ command after mirroring (assuming $$$i$$$ is in the segment) is $$$p'_i = -(p_i - p_{r+1}) + p_l = p_l+p_{r+1}-p_i$$$

    Why does this work? If the last command in the segment was R, then the second last point would be to the left of the ending point, so mirroring about the ending point will make the second point of the new segment to the right, which is what we want. Similarly this can be shown for any position and command on the segment. Finally we need to start at the original segment's starting point, so we shift our new points to have $$$p_l$$$ as the origin.

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

      But isn't it O(r-l) for every query?

      I thought we need to transform the point in query so that it would be possible to check it on straight path stored in set.

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

        I made it $$$O(\log n)$$$ per query by using a map that counted the number of times I visited each point. For a query x y l r: - If I visit x y before the $$$l^{th}$$$ command or after the $$$r^{th}$$$ command, then I visit that point after reversing the subarray - Between the $$$l^{th}$$$ and the $$$r^{th}$$$ command, I check if I visit the point $$$(x_l + x_{r+1} - x, y_l + y_{r+1} - y)$$$.

        To do this I sorted all the queries by l, and then updated counts of x y outside each segment and the transformed point inside the segment by using something similar to a sweep line method.

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

          Yes, you are right. Simple set of points without visit time is not enough.

          But two simple sets are enough :) One to track from beginning and one to track from the end. I'll check this idea.

          upd: seems like even two sets without proper command times are not enough

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

Damn, it's so sad I couldn't solve C in time, it was really easy

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

Will Hashing Not Work in E, I was getting WA on test-5 :(

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

How to solve D without Mo's ?

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

    Pre-calculate times when you visit each position when moving forwards and backwards, plus some prefix sums to calculate the x and y offsets, then you're done!

    Basically this, I have been heavily commenting my solution during the contest 235604170

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

    After reversing, suppose :

    x = s1 + s2 + s3...sl-1 + sr + sr-1 + sr-2.. s(r-z+1)

    => x = prefix_horizontal[l-1] + prefix_horizontal[r]-prefix_horizontal[r-z]

    => prefix_horizontal[r-z] = prefix_horizontal[l-1] + prefix_horizontal[r] — x

    Similarly, prefix_vertical[r-z] = prefix_vertical[l-1] + prefix_vertical[r] — y

    hence there's an index l-1<=z<=r such that,

    prefix_horizontal[r-z] = prefix_horizontal[l-1] + prefix_horizontal[r] — x

    prefix_vertical[r-z] = prefix_vertical[l-1] + prefix_vertical[r] — y

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

How do you check in D whether you reach the point during the reversed section? I just guessed.

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

    If you are choosing it inside the reversed part a[l,...,r]. Then it is choosing a[1..l-1] and a prefix from reversed(a[l...r]) which is suffix from a[l...r]

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

My screencast of solving A-F
I'm planning to discuss my solutions (~2 hrs from contest end time)

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

Can anyone tell what is causing runtime error in my solution? 235592760

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

abs() dont accept long long in c++ are there any workaround other than to manually calculate it? I got WA in Problem C because of this.

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

Can anybody tell me where did i go wrong in the code? problem B : https://codeforces.com/contest/1902/submission/235598766

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

guys i want your help in identifying problem in my code, https://codeforces.com/contest/1902/submission/235602795 this is my solution for C, i first calculate the gcd of consecutive elements and then select a(n+1) by binary search,

i am getting runtime error on test case 2 with exit code 3 particularly on

16

9 -10 -7 4 -8 10 -5 -1 -9 8 3 -2 2 5 0 -6

the thing is when i run my code on my computer i get the correct answer, i have tried almost everything but can't figure out the problem

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

Can someone tell me why 235600689 underflows/overflows but 235608975 does not?

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

Few more contests like these and I may reach Specialist

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

Can anyone tell why this code gives TLE?

https://codeforces.com/contest/1902/submission/235611299

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

For problem C, I spent about 50 minutes just for the runtime error with n = 1, long long difs[n - 1], difs[0]. Lesson learned for me. So glad to finally solve it on time.

Thank you guys for the contest!

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

For me B was really frustrating. C was very good though!

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

For B. Getting Points, although a mathematical formula exists, you can use Binary Search for ease of implementation.

The total tasks created will always be $$$(n + 6)/7$$$.

Suppose you take $$$r$$$ rest days. Notice that it's always optimal to take the first $$$r$$$ days off (so that you never run out of tasks). Since there are $$$(n - r)$$$ working days, and each day you can do at most 2 tasks, the points gained is $$$min(n + 6/7, 2*(n - r))$$$. The points gained via lessons is of course $$$(n - r)*l$$$.

Submission

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

Can anyone share a typical case where C can fail?

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

This educational round was really educative, enjoyed it a lot :)

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

Problem D was cool. Enjoyed solving it. Overall a great educational round.

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

Don't understand why to use binary search in B.

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

    you don't have to use BS. But fixing the days makes the math easier to not mess up. It introduces new errors that may be caused by binary search, though. In my opinion, its about preference.

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

.

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

Hope to become Master tomorrow, first time solved all problems in a contest.

I solved today F in O(n log^3 n) and O(n log^2 n), but the solutions are running in almost the same execution time.

Upd: My O(n log^2 n) solution dropped from 3200 ms to 700 ms after I used vector::reserve in N vectors of size at most 20

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

https://codeforces.com/contest/1902/submission/235605516 could someone tell me, why am i getting TLE here? It should work in O(nlogn) which should easily pass for 1e6, right?

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

in problem D ,Can anybody provide me a idea on how to check within ranges from L to R

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

Bad problemset. Couldn't solve one

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

    really cannot believe you are blaming contest for your bad level you have never solved a single problem in any of your contests and you are still nagging

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

Surprisingly, really good contest i would say. Thanks for the authors! I really liked problems C and B. Idea behind B was clear, but solving it in O(1) took a lot of time). C was tricky to find the idea, but if you figured out how to take last element you can easily write it. Hope one day will have time and passion to open D,E problems!

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

I misread problem C and ended up giving up :< I hope I wont be kicked off Expert

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

Solved E for the first time in a Div.2 contest. Used Trie Here is the code

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

Can anybody give me some problems that are similar to B, please? I feel uneasy when I encounter such a problem.

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

    just solve randomly rather than looking for problems similar to some particular problem

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

What knowledge do D & E require?

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

Could someone give an example on how my code failed ?! I can't imagine the test case .

[submission:Hacked C Solution ]

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

I feel that isn't it impolite to write hash cross code to someone else

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

My Nlog^2N solution for D

  1. Think in terms of displacements on the X and Y axis.
  2. For a query L,R — (x,y) either lies in the prefix, the suffix or the middle region.
  3. Traverse the string forward and note down the points/cell reached at ith index for each i.
  4. Build a segment tree(each node contains a vector of pair representing all displacements that are achieved via this path) over this forward cells array and then to check if (x,y) is reached either in prefix or suffix: query the tree from (1,L-1) and (R+1,N) for (x,y)
  5. To check in mid region: build a segment over reversed array. Now you need to query if at any point in reversed section you can achieve the required displacement.
  6. Required displacement: since you have already moved prefix(L-1) so required displacement is Target — prefix(L-1).
  7. Reversed section starts from N-R+1 and ends at N-L+1. The origin here is already displaced by reversed(N-R). So account for that.
  8. Query the reversed segment tree for required displacement.

Submission link: https://codeforces.com/contest/1902/submission/235635773

Segment tree library used: https://youtu.be/K-86mKNAsmU?si=bI_IBJVNU50Mjysf

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

I solved one (A) question, will my rating increase?

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

Can anyone give me some tips for the hell C? I'm totally confused by it

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

hoping i will become pupil after this round

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

hoping i will become pupil after this round

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

i'm wrong

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

Can anyone please explain how to do C? How to apply GCD there ?

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

    recall that all the numbers are unique.. also, as x is +ve you cannot decrease any number by adding x to it.

    now, we need to reach a common number that can be achieved by adding x multiple(or zero) times to all the numbers. Also, assume that a is sorted initially, so we are willing to achieve:

    a[0]+C1.x, a[1]+C2*x, .... , a[n-1]+Cn*x which makes a[0]+C1.x = a[1]+C2*x = ..... = a[n-1]+Cn*x

    so what you can see here is that we need to maximize x, also, greedily we can see that best choice for that final number as of now would be a[n-1], so we see that for any i, a[n-1]-a[i] will be some Ci*x, so take gcd of all such terms and find x.

    then the probem remains to find optimal the An (try it yourself, if you cant I can help there).

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

      Hi akshat,

      Initially how i thought was, the best option to make array equal is making the array elements equal to the max element present in array.

      So what i did is found the max in array, for ex : a[] = [1 -19 17 -3 -15], max = 17; as the difference among (max — a[i]) should be multiple of x, so i thought x will be in range x -->[1,16], For which ever x is possible i have collected minimum answer(traversed whole array to check x is possible or not, which ever x is possible collected max-a[i]/x)may be here i can use GCD to find x right ?.

      I think u are also saying to make array equal to max right ?

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

        Yes the idea is same as mine. You can look at my code for any clarifications :)

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

    You're adding same x to all elements, if difference between them is not multiple of x they'll never become equal.

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

Why does my nlogn solution timeout for D? submission — 235579778

Update — So many other nlogn solution also getting TimeLimitExceeded , any explanation?

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

What's wrong with my solution 235568240 for C ? Please help me where it is leading to TLE

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

GOT FST ON D . Why they not include such big/Edge test in Pretest.

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

Why so late Editorial?

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

F can be done in O(n*lognlogA + q*logAlogA) with centroid decomposition. while decomposing the tree, just solve all the queries whose path includes the current centroid. We can do this by rooting the current subtree in the current centroid and calculate the xor base for every path from a centroid to a node in the current subtree(O(nlognlogA) in total) and then we can answer a query in O(logAlogA) by just merging 2 xor bases.

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

    hey, can you explain your decomposition part a bit?

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

      Lets say that you are currently solving your problem for a set of nodes S and a set of queries Q. When solving for S and Q, if you find a centroid C in the tree that is consisted of nodes in S, then every query from Q will either contain C, or not contain C. Those who contain C we will solve by precalculating xor bases for every path C->X, where X is in S, and then to answer a query (X,Y,K) we can merge the 2 paths that we precalculated C->X and C->Y and get the answer to our query. Now we decompose the tree into new trees, every query in Q that didnt contain C will now belong completely to some of the new trees. So that means that now we have new subproblems (S1,Q1),(S2,Q2).... which we can solve recursively.

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

my $$$O((n + q) \cdot log_2n \cdot (log_2a_i)^2)$$$ solution on problem F using binary lifting and xor-basis passed during the contest but got TLE on test case 90 on system tests. and an optimized one passed with time complexity $$$O((n \cdot log_2n + q) \cdot (log_2a_i)^2)$$$ after the contest. Is there any solution with better time complexity, like for example $$$O((n + q) \cdot log_2n \cdot log_2a_i)$$$?

UPD: stefanbalaz2 just posted one 2 minutes ago. ty and what a coincidence.

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

    I have other solution too, using LCA binary lift. submission

    Idea: For each node from root you can mantain the height where a new number is added to the xor-basis and the number added, when you are building the base in a child, you need to try do add only numbers added in the parent, thus at most 20 numbers will be added and at most 20 operations will be needed to know if a number will be added or not. for queries, I need to get the height of lca and add all numbers from basis of the nodes u and v up to the height.

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

Hi, can anyone tell me how to hack "String hashing" solutions, just give a link to an article.

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

unrated?

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

When will rating be updated?

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

235603985 This submission was done in contest and gave AC a the time. I woke up this morning with a TLE. 235708991 This submission is exactly the same and still gives AC.

Can someone explain? It passed all hacks and the code is the same. Just one gives TLE and the other doesn't.

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

@awoo@BledDest Thank you very much for the contest. Could we please get the editorials and ratings change — many thanks!

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

    Most contests are rated within minutes of system checks completion. This one had hacking session finished over 15 hours back and still not rated.

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

why this contest do not affect to rating's ?

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

When editorial will be released ?

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

Oh my stupid me... In problem C, I assumed we must choose A[n+1] > 0, then got confused why it wouldn't work :(

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

When Editorial will be released?

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

after how much time does the rating changes come for educational rounds?

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

I'm sorry but when rating changes ????

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

Can you guys tell me if my ratings could go up? 1902C - Insert and Equalize

Click here to see my blogs

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

In problem E, I used string hash and chose modulus 131, got AC during the contest but got WA on test 24 after contest. I tried 135, WA again on test 98. Finally I chose modulus 29123 and got AC. Could anyone tell me how to avoid such situation ?

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

    Always use double hashing

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

      I used double hashing. Double hashing can be wrong if choosing unlucky modulus.

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

        131, 137 is common module for hashing so tester use some test case where your code will get WA . So use those prime module that is not common. Obviously not use 135 as a module cz that not a prime.

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

          Thanks. I think I refer to some code template which is not so good.

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

    here is my wrong submission 235733205 and right submission 235733378

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

    I understand now, 131 is not mod number, it is base number and should be prime.

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

ratings please..

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

When will the ratings change

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

ratings?

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

Go everyone "WHERE IS RATING!!!"

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

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

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

is this round declared unrated?

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

If you want to decrease my rating, do it quick :(

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

Any ideas why is the contest showing up as unrated for me?

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

Why unrated?

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

Where are ratings???

MikeMirzayanov
awoo
BledDest

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

No rating update?

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

For D. I was thinking of a modified version of binary search on the string (landing on mid-point, and then deciding whether the left half or the right half can land me on the target point) — by this, I can answer each query in $$$O(log n)$$$ time. (reversing of string is trivial)

Can this approach work?

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

I have got a message that unfortunately my solution 235585909 for problem C coincides with another solution. I don't know how did it happen. I used IDEONE. Maybe that could be the reason.

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

Regarding the mail -> Your solution 235540146 for the problem 1902A significantly coincides with solutions agrahariprajjawal5/235540146, iit2022164/235540396. Such a coincidence is a clear rules violation.

This has happened because of the use of a common source published before the competition. It happened because of the same template I and the other fellow user use. The template is taken from some internet source which I don't exactly remember. Unfortunately, the code inside the solve function also matched which is a mere coincidence. It's not strange that such small piece of code get matched. So, this is a mere coincidence and please revoke the submissions of mine done during the contest. I agree on providing more clarification regarding this.

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

guys after the rating recalculations this contest was marked unrated for me while I'm still a newbie and haven't gone to 2100 to make it unrated why?

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

Can anyone help me in a OA? I'll pay