soullless's blog

By soullless, history, 10 months ago, translation, In English

Hello, Codeforces!

I am very excited to invite you to our contest Codeforces Round 1037 (Div. 3), which starts on Jul/17/2025 17:35 (Moscow time). You will be given 7 problems and 2 hours and 15 minutes to solve them.

The problems were authored by me, __rose, Pishka12, Chalishkan and I_HATE_MD_DM to solve and alter them.

The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory 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, then the round will be rated for you.

We would like to thank:

GL HF!

Editoral is out!:

Also I would like to show you the beauty of our country's nature with the stunning backdrop of tourist Peak (3965m)!

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

»
10 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Hope to reach Expert in this legendary contest!

»
10 months ago, hide # |
 
Vote: I like it +93 Vote: I do not like it

It should be 4009

»
10 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

as a tester this round is good

»
10 months ago, hide # |
 
Vote: I like it +58 Vote: I do not like it

as a tester this round is peak

»
10 months ago, hide # |
 
Vote: I like it +42 Vote: I do not like it

As a problem setter, I hope you will enjoy these amazing problems.

»
10 months ago, hide # |
 
Vote: I like it +42 Vote: I do not like it

As a first time tester wish positive delta for the ones who r ready to sacrifizs anything for it

»
10 months ago, hide # |
 
Vote: I like it +33 Vote: I do not like it

i was at this peak and the views as beautiful as the tasks on this contest) gl & hf for everyone

»
10 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

As a non-tester, I want to test a round, please some coordinator allow me to do one!!

»
10 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

as a tester have fun everyone

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope to get back to specialist this round (skill issue)!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope to reach Expert in this legendary contest!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

giving credits to the fathers of internet is a sweet gesture ^-^

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I'm so excited — the contest is finally coming

»
10 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

As a participant, I can guarantee there exists some undiscovered peak, 44m higher than this.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Ah, if only I could become an Expert in this contest!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope to be cyan

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a participant, I don't think tourist's peak is 3965 cmon guys

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Tourist has exceeded the peak.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In Round 1035,I got 128 rating and reached Expert,but in Round 1036,I lost 103 rating so I back Specialist. All in all, bless i can reach Expert again:)

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hope I solve A — D

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

hope to reach green!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

"Vinton Cerf, and Robert Kahn for inventing the internet." Ok this was funny lol

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a hike-aholic, the mountain successfully drew my attention!

»
10 months ago, hide # |
Rev. 4  
Vote: I like it -39 Vote: I do not like it

im sorry guys, pls dont downvote me, i just want contribution

»
10 months ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

As a tester, I wish everyone a smooth contest, green submissions, and a positive delta.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How does it work if I participate in this contest, but after rollbacks I become expert right before the contest?

»
10 months ago, hide # |
 
Vote: I like it +15 Vote: I do not like it

As a first time tester, this is definitely one of the peak rounds of all time ( glhf everyone :) )

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Saar singhsoumya_coder, please redeem uncode cards in this round to have your honorary 5-th skipped Div3 contest Saar !! Show them you are unbeatable in code obfuscation Saar !!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I HAVE to participate

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Glad to see that this round was tested by people of all ranks. I hope the problems are good.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hmm

»
10 months ago, hide # |
Rev. 2  
Vote: I like it -59 Vote: I do not like it

.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope to make a comeback

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

tourist peak

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a non tester I hope to have access to the contest questions on advance

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hey guys, I am on a journey to get a coloured rank. If I flopped in this contest, the roast is free—no need to hold back.

It motivates me.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You can do it, bro.

    A bamboo doesn't grow an inch for about 3 years before it grows to around 90 feet in just a couple of weeks.

    I've been stuck in newbie for more than a year

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Expecting as usual another round of div 3 that C or D will be harder than the next.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope that D is not mind-tricking :)

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I find mind tricking problem enjoyable, since I don't know many ad-hoc problem

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

After a 10 days long break...

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why are geometry problems so rare in codeforces. I would love if problem setters made more geometry problems instead of Constructive or Permutation. though i don't hate them

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope to solve 4 problems in the round.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I will reach pupil in this one! :muscle:

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Has something changed my penalty meter kept increasing it was 100+ even though i did no wrong submission?

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Loved F. Errichto's video about heavy/small nodes came helpful. Also amazing test prep for F. I had to safeguard memory + use unordered map with custom hash

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    Author's solution uses only maps and dfs

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      would love to see that. as soon as I saw that it depends on degrees, I immediately did heavy/light nodes. Got 5-6 TLE's and one MLE. one WA too cuz I forgot heavy-heavy case. but overall an amazing problem

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Thank goodness, I was confused after seeing very lenient constraints and hearing about $$$\mathcal{O}((n+q) \sqrt{n})$$$ from everyone I asked, while I had $$$\mathcal{O}((n+q)\log {(n+q)})$$$

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I thought everyone will solve like this

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        There also possible to solve $$$ O(n+q) $$$

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          my $$$\log$$$ was from a std::map, so I would guess your solution uses hashmaps to reduce one $$$\log$$$. Not sure about existence of any deterministic $$$\mathcal{O}(n+q)$$$.

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
             
            Vote: I like it +1 Vote: I do not like it

            No i just answered query separately by their color, and did some math

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
            Rev. 2  
            Vote: I like it 0 Vote: I do not like it

            I think that you can use radix sorting in base $$$n$$$ to perform number compression, then just use a static array instead of a hashmap. This provides a deterministic $$$O(n+q)$$$ solution under the given constraints.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      F is a good implementation problem, my solution also uses maps and dfs 329523385

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    one can use an array which tracks how many colours does a single colour shares edge with,

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Could you please share the link to his video? I couldn't find it on youtube

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I think using unordered_map with default hashing is fine, because the keys passed to unordered_map is small enough (up to $$$2 \cdot 10^5$$$). My solution using unordered_map (329528711) has passed and is fast enough.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Can you specify which video, I'd like to watch it.

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Noice, good questions for my first ever contest ever. was scared to start codeforces but finally gave it a shot after 8 months of DSA grind. how well of a performance is 4 questions?

»
9 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

How to solve A?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I was in queue for A submission for like 3 mins like what was that

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    it's common situation on Div 3/4 round; Therefore, use m1/m2/m3 codeforces

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

damn math questions damn damn damn

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Well the questions were so good. I have given the contest for the first time. I am beginner so my goal was to understand the question. So I solved 2 questions out of 8 and understood the other 3 problem statements but couldn't do it.

»
9 months ago, hide # |
Rev. 3  
Vote: I like it +12 Vote: I do not like it

Problem F is cool

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

problem $$$F$$$ was cool, I think this is the first time for me to use some SQRT decomposition technique in a live contest xD

also, some solutions for problem $$$G$$$ worked on the hard version but got TLE on test 17-18 on the easy one !^_^

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In D , to think of boundaries as l ans r were given variable names but was a distraction.

  • »
    »
    9 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Hi can you share me your approach for D. My Approach is failing at test case-2

    My Approach (Failed)
    Code

    Edited:

    I figured out out edge case

    Edge Case

    I was using DSU like approach to merge all casinos with overlapping intervals into same group and assigning them their largest reachable value, but turns out we can't win any value within range [l,r] for a casino, rather we would have a specific value 'real'. Thus we can't guarantee that we can play at any casino which will have an overlapping interval

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Sorry but I am unable to understand your approach properly, but let me say this that think very greedy, maximizing coins is the goal so sort real[i] array and check if you could achieve the next or next to next or next to next to next and so on.. Thank you

    • »
      »
      »
      9 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      You can just simply sort the array in the increasing order of their realis. Then start iterating and check if you can play on that casinos for that {l<=k<=r} and also check if that casino reali is larger than your k {k<reali}

      So the main check will {l<=k<reali} then only update k=reali else just don't play at that casino,skip that .Iterate till end and return the k;

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      329428651 My greedy + sorting approach

»
9 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

This is my first contest. And i solved first two problems. this contest and result will memorable for me.

thank you

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how can even around 12000 users solve question d.

  • »
    »
    9 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    I wasted a lot of time on it until I realized I had missed an important piece of information given in the constraints, that $$$l_i \leq real_i \leq r_i$$$. This makes the problem way easier.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    almost 20% of them are cheaters

»
9 months ago, hide # |
 
Vote: I like it -24 Vote: I do not like it

MathForces

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve pF? I think I got TLE because of the heavy node (the node with large deg)

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Problem E royally f*cked me.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve D mannnn???

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Just use greedy approach,sort the given array based on coins and always consider taking coins because of real<r constraint for each case.One edge case is,before taking any coin check if number of coins is greater than current coin number.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Just sort the casinos you receive by the amount they are going to give you (because going back is pointless) Then you greedily check where you can advance.

    #include <bits/stdc++.h>
    using namespace std;
    
    #define pii pair<int,int>
    
    struct Pol {
        int l,r,v;
    };
    
    bool fun(Pol a, Pol b) {
        return a.v<b.v;
    }
    
    void solve() {
        int n, k; cin>>n>>k;
        Pol *pool =new Pol[n];
        for(int i=0; i<n; i++) {
            int a,b,c;
            cin>>a>>b>>c;
            Pol pl; pl.l=a; pl.r=b; pl.v=c;
            pool[i]=pl;
        }
    
        int pre=k;
        sort(pool,pool+n,fun);
    
        for(int i=0; i<n; i++) {
            if(pool[i].v>pre) {
                if( pool[i].l<=pre && pre<=pool[i].r ) {
                    pre=pool[i].v;
                }
            }
        }
    
        cout<<pre<<endl;
    
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr); cout.tie(nullptr);
    
        int t=1;
        cin>>t;
        while(t--) solve();
    
        return 0;
    }
    
  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I thought about it greedily. If we sort casinos by l. Then, start from lowest l casino and greedily pick casinos that increases the value of coins. We can do this because an increased coin value with always ensure #coins>=l_ahead, where l_ahead casinos with larger l values than current l, and if this new coin value makes us miss a casino, then that casino was useless anyways as this happens when #coins>r. l<=real<=r for any casino is the key

  • »
    »
    9 months ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    You can just store the value in a vector using tuple and then sort the vector on the basis of the first value of the tuple and just iterate over the vector and then just see if coins >= get<0>(v[i]) && get<1>(v[I]) and set coins = max(coins, get<2>(v[i])).

    Time complexity: (O(nlogn))

    see my code for better understanding:329480826

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    problem D idea was based on one of the recent LC problem (in my opinion) i was not able to solve that problem on LC but this time i solved it in 1 go code -> 329490928

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

overlooked the constraint on each value — specifically that l<=val<= r. , kept writing up a graph soln for 30 mins and messed up the whole contest. This is so depressing :(

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve E ?

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    create a list that is lcm(p[i], s[i]) and recreate p and s and check if they are same

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    check if res[i] = lcm(a[i], b[i]) works and if not then nothing can work

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I did something way more convoluted than what's being suggested. I checked if p[n]==s1 and then for i from 0 to n-2: gcd(p[i],s[i+1])==p[n]. Also checked each of p and s are valid by checking if p[i]%p[i+1]==0 and s[i+1]%s[i]==0

  • »
    »
    9 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it +1 Vote: I do not like it

    To construct a valid array a such that:

    `p[i] = gcd(p[i-1], a[i])`
    `s[i] = gcd(a[i], s[i+1])`
    `p[n-1] == s[0]`   // i.e., gcd of the entire array

    We observe the following:

    1. From p[i] = gcd(p[i-1], a[i]), it must be that: p[i-1] % p[i] == 0

    2. From s[i] = gcd(a[i], s[i+1]), it must be that: s[i+1] % s[i] == 0

    3. Since a[i] must satisfy both prefix and suffix GCD conditions, it must be divisible by both p[i] and s[i]. So: a[i] % p[i] == 0 and a[i] % s[i] == 0a[i] must be a multiple of lcm(p[i], s[i])

    To check if such an a[i] is valid, try setting: a[i] = lcm(p[i], s[i])

    Then check whether: gcd(p[i-1], a[i]) == p[i]

    Substitute a[i] = lcm(p[i], s[i])

    = gcd(p[i-1], lcm(p[i], s[i]))

    = gcd(p[i-1], (p[i] * s[i]) / gcd(p[i], s[i]))

    = p[i] * gcd(p[i-1] / p[i], s[i] / gcd(p[i], s[i]))

    So, for this to equal p[i], we must have: gcd(p[i-1] / p[i], s[i] / gcd(p[i], s[i])) == 1

    If this condition fails at any index i, then no valid array a[] exists.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      can you explain a little more

      after some math you reached here : p[i] * gcd(p[i-1]/p[i] , s[i]/gcd(p[i], s[i]))

      why this should be equal to one ?

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Can you please told me why a[i] would be the lcm , and cannot be more than .

      And how testing just for a[i] would be sufficient

      And Thanks !

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Missed the condition l <= real <= r in D. RIP

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Same with me dawg wasted all the time there.i couldn't even do anything

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
if( p[1]!=s[n] ) {
    cout<<"NO\n"; return;
}

I just didn't write this down and missed question E. What is the use of this one condition?

»
9 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Hi Codeforces!

In today's problem E, i was confusing about one thing

What is the difference between gcd(a[i], b[i]) != a.back() and gcd(a[i], b[i + 1]) != a.back(), imo the should give the same value however the first one is WA and the second one is passed

Thanks in advance!

»
9 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

The problems are good, but I think the samples are too weak...

So many penalties I have made...

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I can't think straight about E

how did you guys think about the problem ?

I know it's the LCM but why ?

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Beautiful problems, especially F! Really enjoyed solving the tasks :)

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem F, I'm seeing a concept of heavy light decomposition. Can this problem be done without it or is it necessary? Was trying to optimize cost update by storing what is the total edge cost for particular color of neighbors for every color and every node, but didn't work.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve G2?

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +6 Vote: I do not like it

    I had a solution where I fixed the minimum element of the subarray (let's call it x), and the goal was to find the maximum possible median (y) of any subarray that contains x.

    It's not hard to prove that the subarray must either start or end at x, because at least one half (either left or right) need to be dominant so we will only take that part so it is just finding the maximum prefix/suffix starting/ending from the index of x (we are going to model the problem for prefix).

    Now, for a fixed x, we can binary search on the value of y. For each candidate y, we transform the array into +1 if the element is ≥ y, and -1 if it is < y. The idea is that if the number of +1s outweighs the -1s in a subarray, it means elements ≥ y are in the majority, so the median has to be >=y.

    To efficiently check this, we use persistent segment tree to find the maximum prefix sum starting from index of x. This can be Done with a combine function where answer of node represents the maximum prefix sum in the current node => answer of current node = max(answer of left node,(Number of Elements >= y in left node + answer of right node)).

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      you don't need a persistent segment tree

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      How do you fix the value of x? Checking each x isn't optimal and doing binary search for x doesn't make sense either.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        You can fix the minimum with NSE and PSE and for a fixed x you are doing binary search on the maximum median

    • »
      »
      »
      9 months ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      i think you should try fixing median

      like common technique build array with ele greater than med as 1 and ele less than med as -1 then find subarray whose sum>=0 ans update ans = max(ans,med-min).

      to do this just iterate medians from n to 1 and maintain segment tree and whenever you update pos of your median as 1 in segment tree you call update query now we can say that our answer can grow if subarray include this position so when you are calling update you go to those l,r which include this positon so while calling update you also try to update your answer just maintain max prefix sum max suffix sum total sum and min elemet in segment l,r

      now when you are standing at l,r

      now you have 3 options

      option-1 if(sum of l,r) >=0 ans=max(ans,med-minimum of l,r)

      option-2 int val=maxsuffix sum from mid to l

      now query the prefix mid to r such that val+prefix>=0 and find the minimum in element in this

      prefix and update answer ans=max(ans,med-miniprefix)

      option-3

      int val=maxprefix from mid+1 to r

      now query the suffix mid to l such that val+suffix>=0 and find the minimum in element in this

      suffix and update answer ans=max(ans,med-minisuffix)

      just check my implementation

      https://mirror.codeforces.com/contest/2126/submission/329546875

»
9 months ago, hide # |
Rev. 2  
Vote: I like it +4 Vote: I do not like it

I tried to hack others' solutions of F but I got unexpected verdict. Could anyone point out my mistakes please or is there anything wrong like this ?

generator

Edit: it works now

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    btw, the tests of F is really weak, and solutions of O(nsqrt(n)logn) could easily pass, and this generator could hack them

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    I'd assume it's the trailing \n.

    Hacking doesn't like extra spaces.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I replaced \n with endl but it doesn't work ToT

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it +8 Vote: I do not like it

        I mean, remove the ending \n entirely. No extra whitespace should remain in the test case.

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it
          Spoiler

          Hack like this? But it doesn't work, or sorry for my misunderstanding.

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it
            Code
»
9 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

Today's F is one of the best problems I've solved in the last few months. Perfect Contest :)

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Editorial??

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Me during contest: A-F: that easy? G1-G2: that hard?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

First time solved till problem D

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

wonderful div3, thank you

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how to solve F?

  • »
    »
    9 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    let's say when you change color of a vertex from x to y, then result += score[color[x]]-score[color[y]].

    You should init the trees with dfs/bfs to set up the color map (for its children) and its parent color update(just 1 edge) for easy update. Overall complexity should be O((N+Q) * log(N+Q)).

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone to help me, why this submission has TL https://mirror.codeforces.com/contest/2126/submission/329511588 Logic: Sqrt-decomposition by questions. I support values for question vertexes and recalc all variables when we have many questions. gg — graph for question vertexes Sorry, my english very bad

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

tried solving G1 with ordered_multiset to get the median but got TLE, can anyone explain why?

submission link: https://mirror.codeforces.com/contest/2126/submission/329538028

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone please provide solution for F with HLD.

»
9 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

While reviewing the preliminary contest standings, I found two contestants whose activity appears suspicious: they submitted solutions to every problem within minutes, and the coding style differs markedly from one submission to the next.

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Hi guys, where can I find the tutorial/editorial? Or is not out yet... this my second contest so im kinda lost

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it
»
9 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

HOPE TO REACH PUPIL IN THIS LEGENDARY CONTEST 10/10! FROM MYSIDE

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Oh man, for the C problem I was just checking the exact difference between jumps although should've been that exact or can be less than that. Totally missed this, just now changed == to <= and it got Accepted.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F was very cool

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My best performance ever! Waiting for rating update ^^

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hey Can Anyone tell me that I have given my first contest untill then I was unrated and I have submitted my first problem which got ACCEPTED but my account is still showing unrated

»
9 months ago, hide # |
Rev. 2  
Vote: I like it +5 Vote: I do not like it

Problem F can be solved in $$$O(n+q)$$$: 329562348.

When I first thought of the problem, I thought: oh, just use sqrt decomposition (heavy-light partitioning). But then, I thought: Why was the graph being a tree? I realized there's a much simpler solution that exploits this constraint.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Nice contest. Thank you authors

»
9 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

E was a shitty problem

»
9 months ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

First live contest this year, editorial taking longer than usual... I miss super-fast editorials :=(

»
9 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

主题:申诉 Codeforces Round 1037 (Div. 3) 被标记 Unrated 管理员您好: 在 Codeforces Round 1037 (Div. 3) 中,我的提交被判为 Unrated。根据官方 FAQ,轻度 AI 辅助(如润色、重构)是允许的,我在此说明: 所有题目的算法思路均为原创。 以 F 题为例:我自行设计「按节点度数分类,小度数暴力、大度数 map」的做法。 AI 仅用于润色我已写好的代码(变量命名、缩进、注释),无任何逻辑复制。 我已核对最终代码,确保无公开模板逐字重合。 恳请复核,将该场比赛恢复 Rated。如需进一步信息,我乐意配合。 感谢!

Subject: Appeal for Unrated Contest Codeforces Round 1037 (Div. 3) Hi Codeforces team, My submission in Codeforces Round 1037 (Div. 3) was marked Unrated. Per the official FAQ, light AI assistance (styling, refactoring) is allowed. Here are the facts: All algorithms are my own. Such as problem F, I personally devised the “degree-splitting + brute-force for low-degree vertices + map for high-degree vertices” approach. AI was used only to polish my own draft code (renaming, formatting, comments); no logic was copied. I have double-checked the final code and confirm it does not match any public template verbatim. Please review and restore the Rated status. I’m happy to provide any extra details. Thank you!

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    关于我为什么要用AI润色代码,因为我要给学弟学妹解释代码是什么意思,我自己写的代码风格不太好阅读,所以我需要用AI在不改变代码逻辑的情况下让代码更适合新手阅读。我保证所有题目的算法思路都是我自己想的。请求恢复rated,感激不尽!

    Regarding why I used AI to polish my code: I need to explain the code to my junior classmates, but my original style is hard to read. Therefore, I used AI solely to make the code more beginner-friendly without altering its logic. I guarantee that the algorithmic ideas for every problem are entirely my own. I sincerely request that this submission be reinstated as rated. Thank you very much!

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +16 Vote: I do not like it

      Sir your code isn't skipped and why are you exposing yourself that you are using AI in contest?????

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

did rating not update or did i register unrated?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi guys, can anyone please tell me when will my rating appear

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How do you do G man I don't understand

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My submission of 'B' got TLE on test case 7 in system testing. I think, at least the first 10 test cases should be capable enough to reject a submission during contest... I am feeling so saaad...

»
9 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

And its joever, TLE on C during system testing, yeah -ve delta for sure.

Edit : D as well yeah I am cooked.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I submitted a, b & c solutions and all of those got accepted without a fail, but know during testing i see only first problem is showing as accepted and second question time limit exceeded and third question is not even showing . Can anyone tell me the possible reason?

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    All the questions go through system testing according to the time they were submitted in the contest. Your last question might not have been tested yet as the system testing is still not completed. Wait till it finishes you will see the final verdict on all your questions

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

is system testing always this long

»
9 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

How weak the pretest is?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Successfully solved the problem D during the contest , verdict was accepted and also on problem dashboard the colour of the problem was green .

But as now I visited the page verdict is in queue and also the colour of the problem is red.

What can I do regarding this !!!

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    System testing is in progress. Once it’s complete and your code passes all test cases, the status will be updated from queue to AC (During the contest, submissions are tested on pretests. After the contest, they are evaluated on the full set of test cases, since hacking was allowed in this round, your code will also be tested against any newly added successful hack test cases)

»
9 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

WTF IS TEST 51 IN F?????

»
9 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

im never doing a d3 or edu ever again... i get fst literally every time for the dumbest reasons, i mean cmon you couldve EASILY put a case in e to stop that

»
9 months ago, hide # |
Rev. 2  
Vote: I like it -12 Vote: I do not like it

why the my solution for the E is skipped??

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    Maybe because it's too obvious you cheated?

    • »
      »
      »
      9 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it -44 Vote: I do not like it

      using two accounts is wrong!!

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it +9 Vote: I do not like it

        That is what called cheating. you avoided your WA in 2nd account. And, used same soln. Don't use multiple accounts for a single contest.

        What is you did is a plain CHEATING.

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
          Rev. 2  
          Vote: I like it -26 Vote: I do not like it

          getting plag- is obvious._

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
             
            Vote: I like it +5 Vote: I do not like it

            Multiaccounting to avoid penalty is 100% considered cheating, cheating doesn't just mean taking solutions from other people / LLMs

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
             
            Vote: I like it +4 Vote: I do not like it

            No matter how much deny. What about those people who solved in one go. While you made mistakes in one account. And used other account to submit final soln.

            Proper Misconduct behavior. This is regarded as CHEATING.

          • »
            »
            »
            »
            »
            »
            9 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            Using multiple accounts in a rated contest is against Codeforces policy. See Mike's blog on this matter.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Using an alt account is a form of cheating — you should have read the rules more carefully. Also, you tried to evade penalties by submitting with your alt account first, which is not allowed either.

»
9 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

The number of hacks in F and G are crazy in this contest.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

interested to know the normal solution to problem E (I just wrote a greedy algorithm for 3 checks and got AC lol)

»
9 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

Fucking Weak Pretest(s) !!! So sad...

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When will the ratings get updated?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my ranking showing 17000 around solved 2 questions will i get any rating for the contest it is still showing unrated. will i get any rating for the contest i had participated first time in codeforces contest

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Ratings are not updated yet for all participants, will be updated soon. The 'unrated' text you're seeing doesn't necessarily mean the contest is unrated for you. That text also appears when ratings simply haven't been updated yet.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i guess i will go to sleep and hopefully see myself green tomorrow ;-;

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why my rating has not come yet?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone help me to debug my submission for F, I am getting TLE at 41th testcase.

Don't know what is getting wrong.

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

editorial when?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

At last, after so much grinding, my name is GREEN for the first time. I'm not fully confident yet, but this definitely motivated me to keep working even harder.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

a good contest, thanks for the author.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

insanely weak pretests for B

come on dropped from like 2k rank to 6k

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Still no tutorial?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

where is the editorial?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

could anyone explain how this brute force is passing for B https://mirror.codeforces.com/contest/2126/submission/329663126

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For the B problem https://mirror.codeforces.com/contest/2126/problem/B why is this code not correct ? ~~~~~

include

include

include

using namespace std; int main(){

int t;
cin>>t;

while(t--){

    int n,k;
    cin>>n>>k;
    vector<int>arr(n,0);
    for(int i=0;i<n;i++)cin>>arr[i];

    int cnt=0;

    for(int i=0;i<n;){
        if(arr[i]==0){
            bool onePresent=false;
            int j=i;
            int daysLeft=k;
            while(j<n && j<=i+k-1){
                if(arr[j]==1){
                    onePresent=true;
                    break;
                }
                j++;
                daysLeft--;
            }
            if(!onePresent && !daysLeft)cnt++;
            i+=(k+1);
        }
        else i+=1;
    }
    cout<<cnt<<endl;
}

} ~~~~~~

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    First, if the current i isn't right, you have to increment the i with 1 only, but you don't do this in the condition (when doing cnt++ you should increase i with k + 1 else you should increment it only 1)

    Second, you will get TLE because imagine that the sequence is k — 1 zeros and 1, and the sequence goes with this pattern, so you need to use binary search to know the next index of 1.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

During the contest, I solved problem D, but to be honest, I just somehow guessed the solution because it seemed that the problem was very similar to some classic greedy problem.

I just experimented with how to sort the intervals. Initially, I sorted the array as I did in the classic problem, by the right side of the interval, and I found that the solution was wrong. So I just changed that to sort based on 'real' instead, and the solution passed, but I didn't understand why it worked.

Can someone explain how to approach these types of problems more systematically? How do you usually prove greedy solutions instead of just guessing?

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I initially doubted that greedy works too, but with the constraint l <= real <= r I couldnt see any case it fails, so I just coded it anyway.

    I thought the only case it could go wrong is when we kind of fail to pick the biggest coin later on for just greedily taking coins, but that could be tackled by storing all coins you got along the way, so I could just implement that later if necessary

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    This is not difficult. This has nothing to do with the size of the right boundary. Let’s assume the number of current coins is x. We can perform the operation when l≤x≤r. We certainly want our number of coins to increase, so this is related to the value of real. When real>x, performing the operation will definitely lead to a better outcome.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can you tell me what's wrong in problem https://mirror.codeforces.com/contest/2126/problem/E

// this is code

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    ll lines;
    cin >> lines;
    while (lines--) {
        ll n;
        cin >> n;
        vector < ll > pre(n), suff(n);
        for (ll i = 0; i < n; i++) {
            cin >> pre[i];
        }
        for (ll i = 0; i < n; i++) {
            cin >> suff[i];
        }
        bool isgoingtonext=true;
        for(ll i=1;i<n;i++){
            if(gcd(pre[i-1],pre[i])==pre[i]){

            }else{
                isgoingtonext=false;
                break;
            }
        }
        for(ll i=n-2;i>=0;i--){
            if(gcd(suff[i+1],suff[i])==suff[i]){

            }else{
                isgoingtonext=false;
                break;
            }
        }
        if(isgoingtonext){
            ll full_gcd = pre[n - 1];
            bool isgoodarray = true;
            if (full_gcd != suff[0]) {
                isgoodarray = false;
            } else {
                for (ll i = 0; i < n; i++) {
                    ll num1 = pre[i];
                    ll num2 = suff[i];
                    if (gcd(num1, num2) == full_gcd) {
    
                    } else {
                        isgoodarray = false;
                        break;
                    }
                }
            }
            // cout << isgoodarray << endl;
            if (isgoodarray) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When will the editorial come?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem D:

t=int(input())
while t:
    t-=1
    n, k = map(int,input().split())
    li = [list(map(int,input().split())) for _ in range(n)]
    li.sort()
    for a,b,c in li:
        if b >= k >= a and k < c:
            k = c
 
    print(k)

This type of codes are accepted. But I think in case of following type of test cases these codes give wrong answer.

3 1
1 3 3
1 2 20
3 10 100

Please correct me if I am wrong as I am newbie.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

when will the toturial come out?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

On problem F

I got the memory limit exceeded because of creating array 2D with size O(N * sqrt(N)) and for each elements got long long int.

After that, I increase the BLOCK size to 1000, still MLE, and 2000 then got accepted.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Toturial?

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Guys, editorial is here — Editorial

I think authors just forgot to add the link on the contest page with announcement

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Appeal Regarding Plagiarism Flag – Submission 329450287 (Problem 2126C)

Hello,

I received a plagiarism warning for my submission 329450287 for problem "I Will Definitely Make It". I want to clarify that I solved the problem independently and did not share my code with anyone, nor did I copy it from any external source.

My solution is based on my own understanding and implementation style, which may resemble others because:

The problem has a relatively standard approach, leading to similar logic among participants.

I use a personal template (macros like pb, all, etc.), which might be common among competitive programmers.

I kindly request you to review my case. I am willing to provide my thought process if required.

Thank you for your time and consideration.

Regards, Bisal Prasad (bisal2003)

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello Codeforces Team,

I’ve received a plagiarism notification regarding my submission for Problem D in Round 1037 (Div. 3). I want to clarify that the solution was completely written by me, and I haven’t copied from anywhere or taken help from anyone.

I don't know how it is happened.I use struct,just because I didn't know about tuple back then.And I used priority_queue just because I couldn't solve in other ways.Using multiple approaces I couldn't even pass the example testcase as I couldn't implemented my idea,that is why I used priority_queue,and it worked.Then I thought if I put all the Real (here in my code which is r) based on l less than equal to current ans,which is initialized by k.After that if I pop the elements less than or equal to current ans,I can get the maximum current ans.That's why I tried this,and got AC.

Now I got this message,I don't know what should I do.I think it's a conincidence. I never face this before.So,I don't know what should I write here. I just can say it's maybe a coincidence from my side,please approve this. I don't know when will you review it.I write the code by my own.This code based on my idea.I always participate fairly in contests and never copied code. Even if you look the code,When I read the problem statement,it was l[i],Real[i],r[i] in this sequence,which I thought mistakenly,as am in time pressure during contest.So I made my custom ds by using struct in this sequence. But I couldn't even passed the example test case.Then I find out I took input in the wrong order which should be l[i],r[i],Real[i].But as it is in contest and time matters,thats why I didn't change the sequence and used r as Real and used Real as r.And my idea was clear to myself.I just came to know that my code matches to others.I don't know how.It's a coincidence maybe.They did this approach also.Here What's my fault?I don't even know.It will be very hurtful,if my submission got skipped.Please review it. And I never used ide.one,I use vscode always. I don't know is it enough to clarify it.But I hope my message can clarify the situation. I am fully aware of the importance of fair participation, and I always code alone during contests. And I assure you I’ve always followed fair practices. I hope you’ll consider my clarification.

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Hello Codeforces team,

I’ve received the notification regarding the coincidence of my solution to problem 2126D (submission ID: 329462957) with several others. I want to clarify that I wrote my solution independently during the contest and did not participate in any form of code sharing or collaboration.

I think this happened because i have given struct name "casino" , and priority_queue as "pq" , which is very common, I think it's just a coincidence

or maybe If this overlap has occurred due to the use of a public or common source that I was unaware of being shared during or before the contest, I sincerely apologize. I understand the importance of fair play and contest integrity and will be more careful in the future, including avoiding any platforms that might unintentionally expose my solutions.

Please let me know if any further information is required from my side. I respect the platform and its rules, and I hope this issue can be resolved.

Thank you for your understanding.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, I had registered for this contest and did not tick the "Unrated" option, but it is showing as unrated for me.
My handle: Amit_2700
Could you please check if my rating update was skipped?   Thank you.