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

Автор FBI, история, 23 месяца назад, По-английски

Hello Codeforces!

I am pleased to invite you all to participate in Codeforces Round 981 (Div. 3), which will start on Oct/24/2024 17:35 (Moscow time).

The format of the event will be like any Div. 3 rounds:

  • 6-8 tasks;

  • ICPC rules with a penalty of 10 minutes for an incorrect submission;

  • 12-hour phase of open hacks after the end of the round (hacks do not give additional points)

  • after the end of the open hacking phase, all solutions will be tested on the updated set of tests, and the ratings recalculated

  • by default, only "trusted" participants are shown in the results table.

I encourage participants with a rating of 1600+ not to create new accounts but to participate unofficially.

Only trusted participants of the third division will be included in the official standings table. This is a forced measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600 (or you are a newcomer/unrated), then the round will be rated for you.

Also, it will be a round with unrated register. If you already registered as rated participant you can change registration type here.

I would like to thank

Good luck!

Upd: Editorial is out.

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

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

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

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

cat

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

finally a div 3 after a month, lets go!!!

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

FBI!Open your mind!

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

How to get +200 in this round?

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

What the heck?By FBI?

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

As a participant... oh wait? I cant be? rip I have class at the time

Ill be sure to virtual tho

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

Finally a contest with usual time.

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

As a tester, I would like to say the Chefir is a very interesting cat.

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

As a tester, I would like to say that all the tasks are interesting, and Chefir in the photo is very cute.

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

Hello! I was a bit late with testing the round, I have sent a message with the feedback, but I am worried that my feedback won't be seen, so I decided to also leave a message here

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

Waga bakuretsu mahou wo kurau ga ii! EXPLOSION!

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

I think I can cross $$$1400$$$ before next Div. 4 round. Since, I opened the account, there's not a single Div. 4 Contest. However, attending straight into Div. 2 helped me to improve my skill quickly.

Anyway, What's the score distribution?

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

cat will help to increase rating

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

What a nice name--"FBI"...

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

As a tester, I hope no one will use AI

»
23 месяца назад, скрыть # |
← Rev. 4  
Проголосовать: нравится +15 Проголосовать: не нравится

Knock Knock !!!

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

To qualify as a trusted participant of the third division, you must: do not have a point of 1900 or higher in the rating.

did you mean 1600?

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

as a tester, this round has problems

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

Bro only sets Div 3!!!

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

Can I pet the cat :)

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

As a tester, good luck have fun

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

Greetings Chefir!

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

As a tester, I respect Chefir orz

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

Is there a way I can submit during contest if I forgot to register before the contest started?

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

Thanks for problem B! In all seriousness how is it even possible to screw the problem statement that bad??

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

Nice F,G. No clue where to even start.

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

problem C is just wow.

i have no word

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

How to do C??

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

    what i did. get all pairs. distribute numbers again greedily considering swapping a[i] with a[n-i+1] or leave them at their original positions.

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

      why does this work

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

        It’s based on a simple exchange argument proof. Basically, at each step you have 2 choices: swap a[i] and a[n-i+1] or not (dp works here too).

        Assume a=[3,3,7,5,3,9,1,7,4], and we are considering swapping a[1] and a[7], in this case, swapping or not leads to the same optimal answer we can get for a[0…2] and a[n-2…n] but this answer is independent of the optimal answers we can get for a[3..n-3].

        Therefore, we calculate the local optima we can get at each step hoping it leads to the global optima. Hope this helps ;)

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

    If n is odd, ignore the middle element. Now take 2 middle elements,let their value be 'a' and 'b'. Let the element to the left of 'a' be 'c' and element to the right of 'b' be 'd'. Note that if a!=c and b!=d, this is best you can get(zero disturbances), so do not do anything, otherwise just swap positions of c and d, because this will not worsen the answer, the number of disturbances will either remain same or it will decrease, in this way move to the end points of the array. At last, you have the modified array with you, just count the number of indices where a[i] = a[i+1]

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

    what i did, fix the first pair of numbers, and then greedily order the rest, and then fix the first pair of numbers in the opposite way, and then again greedily order the rest. and then just take whichever of these 2 is better

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

    I did the following: swap $$$a_i$$$ and $$$a_{n - 1 - i}$$$ if either of these elements are same as their outer elements. By outer elements I mean the element just left of $$$i$$$ and just right of $$${n - 1 - i}$$$ respectively. The final array by iterating till the centre of the array is the optimal arrangement.

    Proof: Consider an optimal arrangement. we will show that any optimal arrangement can be transformed to our preferred arrangement without worsening the answer at any part of the transformation. Starting from the outermost pairs of elements ($$$0$$$ and corresponding $$$n - 1$$$), let's say the first relative order of elements we encounter which is not arranged according to our preference is between $$$x - 1$$$ and $$$x$$$. Now if we swap all the elements from $$$x$$$ to $$$n - 1 - x$$$, they will preserve their relative order, and thus the disturbance for all the elements in the segment. In fact the only thing that changes is the relative order between indexes $$$x$$$ and $$$x - 1$$$ and the corresponding pair on the other side of the centre. So the overall answer will only change due to the change in this part, which we can easily show, will not worsen if we swap it. We can continue to find such out of order indexes and swap them to our preference and none of these flips will worsen the answer.

    Thus, irrespective of the optimal arrangement, we can transform it into our exact arrangement, and the disturbance never got worse. Hence our arrangement algorithm in fact provides optimal arrangements itself.

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

      what is the difference between optimal and preferred arrangement ?

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

        By preferred I mean the arrangement that you propose to be solution, and the optimal is a hypothetical arrangement which has the optimal answer, but not necessarily same as your proposed arrangement. By the end of the argument the goal is show that the preferred solution is optimal itself. Note thatseveral different solutions nay all be optimal, you just need to show yours is one of them.

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

      _ So the overall answer will only change due to the change in this part, which we can easily show, will not worsen if we swap it._

      How can we show that ? I am not getting any idea around that.

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

Was F really that easy (~1500 submissions)? I've been staring at the question for the last 1.5 hours and can't think of anything.

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

Born to make problems for div2. forced to make problems for div3.

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

Good job, guys. Very nice contest!

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

what's wrong in my F .

We just need to multiply Pisano period of k with n in mod ? Right .

I am Getting this 998488007 instead .

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

Great contest, but sadly D is literally on leetcode

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

I solved F assuming that the period of "0" could be different, depending on the first term of the sequence ((0, 1, 1) is different of (0, 2, 2) for k = 4, for example), and this led tosome more unnecessary thinking and code, instead of just finding the first "0" and multiplying the answer by n. Now I see by bruteforcing all k's the period is always equal.

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

Am I the only one who swapped operations in G and ended up solving that for no reason xD

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

what is the follow up for F, i understood it will have a modular cycle, upon some search and reduction i can deduce the : nth fibonacci number as f(n) = (((1 1) (1 0)) ^ n - 1) * (1 0), but how to make progress with this. Any help will be appreciated.

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

    for all k, we can find the first "0" element by linear number of calculations. I bruteforced all k's from 2 to 100000 to find out the maximum number of operations, and that's always lower than 2*k (Didn't prove the general case). For some reason this period is always equal for all k <= 100000 too.

    Here is proved by AC 287807845

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

What's the order of swapping in 3rd question or simply what was the logic behind this question, I tried a lot but didn't got the answer.

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

The problem statements were so poorly worded and sample I/O was not explained. For example, in problem B, you talk about mountain and then suddenly ask at the end about spikes. Mountain is defined to have positive height, but a square of mountain can have lakes (that have negative height). Why even write a legend if you cannot be consistent about it in the very problem statement? sigh

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

F was a sadistic problem

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

What the hell is problem C

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

For E. I got TLE on TC 5, how can I further optimize this?

Submission: Link

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

Please add a note or explain at least one of the test cases. I am not asking for an explanation on every test case of the question, but as a beginner, some questions can be challenging for me to understand. I often look through the test cases and notes to get an idea about the question. Again, I’m not suggesting you add explanations for Problem A; I suggest starting with at least Problem B.

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

Any hints on C and D? My brain is deep-fried and cannot think clearly anymore

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

    C : Think of a swap as penalty increase, no effect on penalty or penalty decrease. Penalty increases after a swap if the ai != ai+1 and we swapped in a penalty value. So we only swap when ai = ai+1 as it will either decrease penalty or will keep it same. I don't know how to explain better than this.

    D : Prefix sum map int -> int. store the last index where the sum appears. Iterate from beginning and if you find some sum again update its last appearance and increment ans.

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

Greedy Forces

»
23 месяца назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +46 Проголосовать: не нравится

who else when $$$k=1$$$ printed $$$n$$$ instead of $$$n$$$ $$$mod$$$ $$$10^9 + 7$$$ ?

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

f is easy to find in google, d < c, excellent round, thanks fbi, now i prefer the KGB

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

G : Try to solve offline....... For a pair ( v , k ) , find node k distance up from v , now if I go up to a node x , ans of query can be level[v] + ( "distance of deepest leaf node from x found so far" — level[x] ) . we can create a array on the basis of inTime of nodes , and use it to find maximum in a range from l to r using a max segmentTree . l : inTime[u] : u nodes after k jumps up from v ( use binary lifting to make it fast ) r = inTime[v] .As soon as a node is done , update its value with — inf in segmentTree

Just want to know is it somewhat related to Heavy Light Decomposition.

Sorry for my weak English

Refer to code

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

what is the solution to F?

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

for E, if you also have to print the swaps, then it's similar to https://cses.fi/problemset/task/1698

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

C is incredibly hard as a 3C

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

Fidelity Bravery Integrity

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

greedyforces. guessforces. readforces.

pA: The problem statement is so long that I need a lot of time to read the statement. Also, no explain testcases makes me more confused. I can't understand who wins on problem A, and I need a lot of time to read the statement again and again. I also don't like the output of A, why not just output yes/no instead of the LONG name?

pB: "If aij<0, then THERE is a lake THERE". Why 2 THERE in the same santence? "With her magic, she can select a square area of mountains and increase the height of each mountain on the main diagonal of that area by exactly one." The sentence is too long, u should split the sentence by "," and ".".

pC, pD, pE, pF are all GREEDY. Why put so many greedy in a contest? To make people guess the ans again and again? pF is the most painful problem among them.

To do pF, we first need to guess that there is a cycle of the remainder of k. Then, guess the upper bound cycle length is bounded by a multiple of k. We just guess everything in pF, that's stupid. Also no need for a ll n in the input, which makes me lose my AC for k=1. Honestly, What do we learn from this problem? Guess? Take care for output of k=1 bcz n is too big?

I learn nothing from this contest. I just guess and guess all the ans from all the problems. Problem statements on pA and pB are fxxking long and really weird, which made me suffer. We DO need the contest to test our CP ability, instead of reading problem statements/guess the ans/avoid the unnecessary traps.

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

    If you think greedy is guessing, then maybe you can try learning how to prove your greedy solutions ;)

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

    Generally agree your perspective on the extremely boring A, B, D and F with awful statements or ideas. But it seems that C can be solved by linear DP and E can be abstracted into a relatively interesting graph problem(about how to optimally cut the long loops). However despite the multiple solutions, this round is still too relied on key observation and guessing as you just said, and F is the most weird amongst all the unreasonable ones. It's just like a guessing game rather than a true algorithmic problem combined with number theory.

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

    I read the problem A half way, saw the test cases and assumed (idk why i risked it) that its just odd/even and AC.

    B was stupid too, I was baffled by the lengthy and confusing statement. C was also not clear in the first instance. went straight for D. really a guessforces.

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

    I feel better after using DP on C instead of greedy. The problem has a single observation to pair the disturbance of i with the disturbance of n-i, instead of n-i+1 as one initially does. The problem also leaves behind one of the repeating pairs count in the description to allow this. You need this "creativity" to solve the problem, regardless of what everyone else says about "proving greedy" or whatever. Fundamentally, it's about math creativity. This means that for the front half of the elements we pair with the element in front and for the back half we pair with the element behind. In doing this the problem of [2,n-1] becomes a subproblem of [1,n]. Then DP follows.

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

loved it I got the idea of F but couldn't implement it out as I didn't focused that we just can brute forced it out man but was a great contest for me

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

hmm

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

I was able to solve problem 2033F - Kosuke's Sloth by making an observation that numbers divisible by k occur at regular intervals in fib sequence (I don't know why)

https://r-knott.surrey.ac.uk/fibonacci/fibtable.html

Then you have to find first index i where fib[i]%k is 0 and another observation I made is that this index i is always less than or equal to 2*k. You simply multiply this index by n to get index of nth element divisible by k.

if you see the table in mentioned link, you will observe indexes —

divisible by 2 — 3,6,9....

divisible by 3 — 4,8,12....

divisible by 4 — 6,12,18.... (huh?)

divisible by 5 — 5,10,15.... (why?)

divisible by 6 — 12,24,36... (what?)

Is there a way we can find the first index using k itself?

»
23 месяца назад, скрыть # |
← Rev. 4  
Проголосовать: нравится -13 Проголосовать: не нравится

B's Statement is too long for 3B

C is hard for 3C

D is somewhat classic

I think F was in hand , if we just had better set and statements

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

What is the idea of E?

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

    You can visualize this as a directed graph where every node i is connected to node P[i]. The given conditions will be satisfied only when all cycles in this graph have a length of 1 (that is i = P[i]) or 2 (that is P[i] = j and P[j] = i).

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

Is it just me, or did anyone else implement G , such that if you move from child to parent, your stamina doesn't decrease, but when you move from parent to child, your stamina decreases.

( basically, direction of travel was reversed :| ) .

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

    but even after that how to solve it?

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

      when we do it in reverse, I guess question becomes even more difficult than the question that is already asked.

      The question that is asked, for that I guess DFS + Segment tree is enough.

      The question that I was solving, we need to maintain monotonically increasing set of nodes, which always improve the answer.

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

        Can you guide me to the solution? How do I start with this one?

        Can we use dfs tree flattening? we can go upto k parents up, then we just want to figure out the farthest node from i within that subtree.

        Is this approach useful? too complicated? any help would be appreciated.

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

          Lets define few terms,

          1) Level of 'node' is equal to distance of current node from node-1.

          2) Maximum depth of the node — in the subtree of given 'node', what is the maximum length of any chain.


          Now do 2 parse DFS .

          First DFS

          In the first DFS, you can keep track of level of node, and maxDepthOfTheNode ( You just need to keep track of two maximums ) .

          Second DFS

          When we travel from 'parent' to 'child' node, we have to find, what is the maximum length chain, that is starting from the 'parent' node, and doesn't pass through 'child' node ( basically passes through sibling of the current child we are exploring ). You need to insert this value in the segment tree. ( Point update in max-segment tree).

          Then it is simple range query for last 'k' elements of the Segment Tree.

          Hope this helps.

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

    i thought that at first when i read it, but thats fairly trivial. edit: its not that trivial actually nvm

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

      IMO, the implementation is little tricky when we do it reverse. The implementation is very straight-forward, if you have max-sementTree template.

      The reverse of the question, was little edge-case involving.

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

        yea i just started thinking about it, and i just realized its not actually trivial at all. i believe segment tree is needed for both of the versions, and sadly i have no idea how to implement it or use it so i can only wonder :(

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

          I was unable to figure out, how the segment tree would help in reverse direction. Please elaborate idea. What values would you store in segment tree ?

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

            It is solvable and i solved it during contest before realizing I alongside 100s of others made the same misreading

            Solution : as in the other solution, we assume we have d_i a depth array calculated where d_i represents deepest node in subtree of i'th parent of v (which is not present in subteee of (i — 1)th parent of v)

            Now, we want to find the maximum of expression

            $$$i + min(d_i, k)$$$

            Find the last index $x$ where d_i >= k using Walk on segment tree. Then, either optimal index is $$$x$$$ or one of the indices $$$x + 1....$$$

            Calculating value for $$$x$$$ is easy, and for $$$x + 1...$$$, you can note thar the function becomes $$$i + d_i$$$ because $$$d_i \lt k$$$, and the segment tree we are already using for this version of the problem suffices

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

              exactly what I did bhai... But instead of using the segment tree, I had used monotonic set of nodes, which will always improve the answer. and then applied lower_bound search on those. couldn't think of SegTree based solution.

              Code for reverse direction

              While running sample test cases, I realised, I am screwed. Although it was good problem to solve.

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

can anybody tell why the code for G problem of this contest is giving tle its complexity is (n+q)logn https://codeforces.me/contest/2033/submission/287818878

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

For the problem f, The proof of the solution is

Let F(i) be the first term when F(i)%k == 0, then the series from the ith term modulo k for every term (F%k) onward will be like F(i-1),0,F(i-1)*(1), F(i-1)*(1),F(i — 1)*(2), F(i — 1)*(3),... F(i-1)*F(i)

Now, we can can say that F(i — 1)%k != 0 since F(i)%k == 0 as we assumed, therefore the 2*ith term which is F(2*i)%k = F(i — 1)*F(i),.. Now carrying on forward, we can say that i,2*i, 3*i, 4*i,... will be the term when F(i)%k == 0.

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

For the problem F ,

what is the proof for the following fact : I brute forced for all prime's up to 1e6 (p) to find index of the smallest fibonacci number that is == 0 (mod p)

here are the values up to 100

as you can see the value is at most n+1 , that allows for submissions like rainboy's to pass as they just naively find the first fibonacci number which is == 0 (mod k) and multiply it by n.

Does anyone has a proof for this , why does this work ?

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

C was too hard for a div3C, totally made for guessing the solution. In D, you could have explained what you meant by non-overlapping, do you consider (a,b) and (b,c) to be non-overlapping? or do you consider (a,b) (b+1,c) to be non-overlapping? Its the former,which i got to know after a WA.

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

    totally made for guessing the solution

    Disagree with this. If you start solving the problem from the middle, the problem becomes quite simple I believe. If we consider the even case, we can fix the middle two elements in any order, because no matter how the middle two are arranged, we can always adjust the rest of the elements relative to them. Now once we fix the middle two elements, we start moving outward. Suppose we are at $$$l,r$$$ currently, now we just need to compare with elements $$$l+1,r-1$$$. If swapping $$$l$$$ and $$$r$$$ results in a better answer than not swapping, then we should definitely swap them. Instead of just swapping $$$l$$$ and $$$r$$$, think of each step as swapping the entire prefix till $$$l$$$ and the entire suffix from $$$r$$$ onwards. If we think of it this way, one can see that only the relationship between $$$l,r$$$ and $$$l+1,r-1$$$ is changing, everything else stays the same. Hence, it is always enough to look at the immediate inner neighbors, and swap if it improves the answer.

    I'm a little surprised that this problem has barely more solves as E. I was a tester and when I was giving virtual contest, this was actually problem B. While I did feel that this might be a little hard for a B, didn't think it's as hard as E.

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

      instead of just swapping land r, think of each step as swapping the entire prefix till l and the entire suffix from r onwards

      Could you explain this more?

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

        Sorry for the late reply, I had gotten extremely busy with some stuff. Hope this will still be a relevant answer to your question.

        I am trying to prove why it is optimal to swap $$$l,r$$$ solely based on their relation with their inner neighbors $$$l+1,r-1$$$. One might think that swapping $$$l,r$$$ might be better with respect to the inner neighbors, but maybe it worsens the situation with the outer neighbours, i.e. $$$l-1,r+1$$$. The answer to this is that, instead of thinking as just swapping $$$l,r$$$, think that you are swapping all of $$$(l,r), (l-1,r+1), (l-2,r+2),....(0,n-1)$$$. Basically the entire prefix till $$$l$$$ is being swapped with the corresponding mirror element in the suffix till $$$r$$$.

        The reason why I tell you to think of it in this way is that if you look at the kind of a swap overall, the only thing that is changing is the relationship between $$$l,r$$$ and $$$l+1,r-1$$$, everything else stays completely the same. Main point being, the relationship with the outer neighbors stays the same, hence this is a counter to the initial thought of 'it might worsen the situation with respect to the outer neighbors'. So we have basically found a way in which we can ensure that we can always get the minimum possible 'disturbance' between every $$$l,r$$$ and their inner neighbors $$$l+1,r-1$$$, which is kind of a greedy approach, since we are able to get the minimum possible answer at every single step, which will obviously result in the minimum answer overall.

        Let me know if you happen to have any further questions or there's a part that's still not clear.

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

          Apologies if it is asking too much.

          With ref to this comment https://codeforces.me/blog/entry/135421?#comment-1211619

          How can we prove the correctness with exchange argument ? Assuming that we have a optimal solution and we can swap reverse the subarray between (i, n-i). ?

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

            When you reverse the subarray from i to n-i, the only thing that is changing is the relationship between i, i-1 and n-i, n-i+1. So that means our operation did not affect anything else, and within what got affected, we got a better answer. So that means that our method will always give an optimal solution.

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

              Ok.

              So exchange argument forwarded is. Start with an optimal solution. And show that we can transform from optimal to our solution without changing "disturbance " at any step we are doing the transformation. While I understand the disturbance not changing anywhere except between i-1, i and mirror of it. Not clear, how it is is proved in the original argument provided by the op that the disturbance of combined disturbance (i, i-1) and mirror is same in the optimal before and after the transformation, which op n as can be easily shown.

              If you have any idea around will be thankful for that.

              Sorry again, to ask you a question for the solution not provided by you.

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

Can someone please hack this solution?

https://codeforces.me/contest/2033/submission/287788123

Thanks!

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

why so many D's are getting Hacked ??

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

    Because of unordered map I think.

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

    Overflow/underflow problems, I assume. You need to use a 64 bit integer map/set key as n = 10^5 and ai can be in range -(10^5) to 10^5, so total sum of a can be -(10^10) or 10^10, which are respectively less than INT_MIN and greater than INT_MAX. As such, I believe solutions that use a 32 bit integer map/set key will be prone to hacks.

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

      Below is a generator for hacking people storing their prefix sum in map/set with 32 bit integer key. It causes an overflow which results in the integer value '32704' to be stored in the map, then carefully adds negative integers until a final value is added to be equal to '32704'. This causes the bugged code to falsely find a prefix sum which doesn't exist in reality.

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

guys my solution got hacked, and i dont really understand how, and what is wrong with it, i'm new to codeforces, can anyone check and tell me why did it got hacked?

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

Does anyone know how to approach problem F intuitively without any googling or guessing the idea. Like ok maybe I can guess the first occurrence of zero must be periodic for all zeros, but how to prove this simply?

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

    This is how i solved: First observe/guess that when you find the first number divisible by k, its just periodic and every x-th number is divisible by k. Then I try and calculate the first k fibonaci numbers and assume that its enough to find the first divisble number. That fails on test cases, but k+1 passes, so i submit. Get WA on test2. Ok so lets just assume that we can calculate it in some y*k time where y isnt too big, and if i just calculate until i find it, it should pass time limits. Submit and get AC.

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

      Ya I thought of that in contest, but here you are still making the guess that after you find the first divisible by k number, you then just output n*k. Is there a proof on why this 0 must be periodic? Like maybe let the first position be x, how do you know there is not also a 0 between x and 2x? This is the uncertainty I had in contest which made me hesitant to submit.

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

huge part of solving problem C is realizing that it's a div 3 C which is a skill that only needed in code forces

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

whats the point of questions like F that require some kind of math theory and code that can be easily generated by gpt. I can assure you atleast 80 percent of the people who did it googled/GPTed it.

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

why did div3 not allow rating???

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

too unfortunate this 287855687 get wrong on problem C. I was soo close

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

good round, solved upto D hoping for pupil soon

got hacked on D for using unordered map though, upsolved using set.

overall a good performance on my part, performance of around 1200 (after hack), 1350 (before hack)

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

why aren't people using two pointer to solve C

It's the approach I got during the contest and it's been accepted. After seeing post contest discussions I see a lot of people saying it should be solved using DP.

I will upsolve but I don't understand why didn't a lot of people solve it using two ptr during the contest.

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

Can someone help my G? I don't know why I got TLE on test 8, plz. 287869462

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

For F: https://www.geeksforgeeks.org/nth-multiple-number-fibonacci-series/ Added a few modulos and raised max n and got AC

»
23 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -17 Проголосовать: не нравится

I was hacked in problem D. I already was unhappy by my performance in that since I was so close to submitting E, I derived the cycle but then failed on figuring out that it would (k-1)/2, I was trying k/2. But then D also got hacked because of something I can't figure out

Anyway,

I submitted this using an unordered_map which got TLE and was hacked :(

void solve() {
	int n;
	cin>>n;
	vll arr(n);
	cin>>arr;

	unordered_map<ll, int> mp;
	ll sum = 0;
	int ans = 0;
	fori{
		sum+=arr[i];
		if(sum == 0 || mp[sum] > 0){
			ans++;
			mp.clear();
			sum = 0;
		}else{
			mp[sum]++;
		}
	}
	cout<<ans<<endl;
}

Then I submitted using a multiset which got AC.

void solve() {
	int n;
	cin>>n;
	vll arr(n);
	cin>>arr;

	multiset<ll> mp;
	ll sum = 0;
	int ans = 0;
	fori{
		sum+=arr[i];
		if(sum == 0 || mp.count(sum) > 0){
			ans++;
			mp.clear();
			sum = 0;
		}else{
			mp.insert(sum);
		}
	}
	cout<<ans<<endl;
}

Isn't a mutiset slower than unordered_map?

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

Given the number of successful hacks for Problem D , it is so that deliberately the tests are weak so that the contestants can hack each other's solution and earn points?? JUST A POV :)

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

For problem E came up with this solution though cannot prove it and didn't manage to submit by some seconds :-))

Unfold

This basically tries to make permutation and "reverse-permutation" equal in <= N steps.

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

I got tle on test case 49 of D even after using custom hash in unordered_map.

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

I think question G is better than question F, question F can be written quickly by guessing the conclusion, and question C is also more difficult than question D and E.

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

When will the Rating's Be updated

is there any site that give the expected ones out

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

1259 still newbie T_T

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

Arghhhh, why is https://codeforces.me/contest/2033/submission/287918494 TLEing for G? It's literally segtree + dfs which I hope is intended solution.

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

what is the logic behind G

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

Can anyone help me with my submission for D, I use Java and I've noticed that I am getting tle if I use map.clear() in submission 287709751 but if I re-instantiate the map 287930490 it gets accepted.

Upd: Got it clear function just sets all entries to null by traversing the array and the size remains the same.

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

How can C be solved with binary search? I am asking because I noticed that problem C tags involved binary search for some time.
Also, I am curious to know how these tags are added. Is it detected somehow automatically from submitted solutions? I noticed that after I submitted my dp solutions, the dp tag was added again.

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

    Tags are added by people that can be "trusted" to handle tags properly, and by "trusted" I actually just mean people above a certain rating (I believe that would be CM)

    There actually was an instance when people mass-spammed tags on the D problem, and a similar thing likely happened on the C problem on a smaller scale.

    Circling back to the first question, if a binary search solution even does exist it would be slower than the intended solution for C (as shown in the editorial).

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

How to solve G? Thank you

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

    Note that you can go to K-father from a vertex, and the answer is contributed by any vertex and the path of K-father.

    Let's define $$$dp_i$$$ means a vertex can go to its deepest son of $$$dp_i$$$ length, $$$cdp_i$$$ means a vertex can go to its the second deepest son of $$$cdp_i$$$ length(The paths do not intersect).

    You can get a new array $$$len_i$$$ means the longest path that the father $$$u$$$ of $$$i$$$ can reach without passing through $$$i$$$. It's either $$$dp_u$$$ or $$$cdp_u$$$.

    Now we want to know how long he could go. Note that $$$i$$$'s father $$$u$$$ contributes $$$len_u + 1$$$, $$$i$$$'s father's father $$$v$$$ contributes $$$len_v + 2$$$...

    So if we design $$$len_i$$$ as $$$len_i - dep_i$$$, our mission is to get the $$$\max$$$ on the path from the vertex and its K-father. When get the maximum of the path, add $$$dep_i$$$ back. Remember we have another choice is to go to the vertex's son. Just take the maximum value. Then use multiplication algorithm to solve it!

    This is my submission 287948215.

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

It confused me a lot. I thought my submission 287933697 is totolly $$$O((n+q)\log{n})$$$. Why I got TLE?

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

how did i do d,e,f but not c

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

How on earth is it possible? Problem D, TLE with std::unordered set but works all fine with std::set?

TLE-with-unordered-set

Okay-with-set

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

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

»
23 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -17 Проголосовать: не нравится

Hello, Codeforces Headquarters, Vladosiya ,

I would like to report a false accusation of cheating regarding my code for the last Div.3 E problem.

My code works by checking each unvisited index within a cycle, marking it as visited, and counting the cycle's length $$$(c)$$$ . If $$$c \ge 3$$$ , we need to perform swaps, as each swap reduces the cycle length by two. This results in $$$\left \lfloor \frac{c - 1}{2} \right \rfloor$$$ swaps being necessary.

(I think I've to make screencasts to avoid this ?) + (I've solved some similar problem somewhere)

Please take this into consideration

Thank you.