Proof_by_QED's blog

By Proof_by_QED, history, 8 months ago, In English
Rating Predictions

2137A - Collatz Conjecture

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2137B - Fun Permutation

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2137C - Maximum Even Sum

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2137D - Replace with Occurrences

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2137E - Mexification

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2137F - Prefix Maximum Invariance

Problem Credits: Proof_by_QED

Solution
Code
Rate The Problem!

2137G - Cry Me a River

Problem Credits: SpyrosAliv

Solution
Code
Rate The Problem!
  • Vote: I like it
  • +67
  • Vote: I do not like it

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

speedy

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

Fast Editorial :))

Problem E was hands down one of the most beautiful and surprising patterns of MEX when I figured out the periodicity (though I thought array after 1st and 3rd transformation will be same earlier and received a WA verdict).

Kudos to the setters and Proof_by_QED for such short question's statements and still an amazing Div3 contest (perfect difficulty).

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

Could you maybe add a "Hints" section(like Hints-1, Hints-2, ...) to each problem? It would be useful to get a direction before seeing the entire solution.

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

Fast editorial and really interesting contest! Solved E seconds after contest ended :(

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

Proof_by_QED Can someone please explain why this submission 337439631 gives TLE and this one doesn't 337446927. I am really frustrated because of this.

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

Very beautiful problem E. took me over 20 mins to realize that we only need at most 5 operations before the array repeats between even and odd operations. Very grateful for such beautiful contest. Well done Proof_by_QED.

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

Can somone tell why for E my this code is giving tle — https://mirror.codeforces.com/contest/2137/submission/337387475

for test 12 it has value t = 1 and n = 2e5 and my code has TC of 10*nlogn so shouldnt it pass??

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

    You have to see that you need to apply the operation at most 3 times, and then the new array start cycling over and over again

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

      i did the same in AC code but i am asking about why previous one was giving TLE as per my calc its TC should be 10nlogn so it should pass

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

        Oh, got it. The one that you sent should be 100nlogn (because of ur per value) but I saw ur submission with per = 10 and TLE. If I remember correctly both map and set has a high constant factor that you are not considering, that can be the reason of the TLE (if it is 10 the constant factor you will get the TLE).

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

    https://mirror.codeforces.com/contest/2137/submission/337427179

    well i too did with O(10nlogn) and it passed during contest, although it gave TLE with O(20nlogn). i used set to find mex, and sets have bad constant factor which caused tle, but still it worked with 10. open to hacks if this will also TLE!

    with your case, i am not sure if this is a right way to see but inserting in map and set is taking 2 logn, so overall atleast 2nlogn there, and multiply by 10 making it 20nlogn? well correct me if i am wrong here!

    PS. i used sorting to find mex instead of set, and even O(50nlogn) passed!

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

    https://mirror.codeforces.com/contest/2137/submission/337478022 well yes, i just made your map into a vector, thats all, and it passed with O(10nlogn). i am assuming your previous solution is actually O(20nlogn)

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

The short question statements were beautiful! Loved the contest, altho couldn't solve E, but still kudos Proof_by_QED SpyrosAliv

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

facing this issue can anyone help Recently, your account was used to crawl. Please change your password to prevent your account from being used for unauthorized activities.

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

I didn't solve the G with a BFS on the dp for updating the red nodes.

My solution suppose than all the nodes must be red at the end of the Q requests. How ? I define Ti the moment were a node become red, Ti = q if the** q-st** request color i in red, else if no request color it, I say that Ti = Q+1.

We have to see that if Cry loose when starting at u at time t, he lose at t+1 as well.

So the question became for Cry "What is the latest moment where I begin to lose". I can answer this question just with a minimax dp on the graph with timed weighted edges.

After I just have to compare the time of the querie and the time when cry begin to lose for determine if Cry WIN or LOSE.

Sorry for my bad english.

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

In G, why is dp_2(i) initialized with 0? Initially when there are no red nodes Cry will win from any node even if it is River's turn. Here is my solution that initializes both the DP arrays with 1: https://mirror.codeforces.com/contest/2137/submission/337457768

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

Why does this code not work for F? I use the same logic with a stack but the code WA's on test 2.

337424542

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

    I faced the same problem. You can not calculate prev2 (i.e. that data structure that tells you, for some index $$$i$$$, what is the leftmost previous index $$$j$$$ such that $$$a_j \ge b_i$$$) using that approach. It works for $$$a$$$ because you are comparing elements from the same sequence and the monotonicity invariant does hold.

    Consider the follwoing test case:

    a = [2, 1, 1]
    b = [1, 3, 2]
    

    Your code will output $$$0$$$, while the correct answer is $$$1$$$. I solved this problem by using a segment tree.

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

what exactly previ is in problem F editorial ? is it the left most or the right most index

i did the right most and then for each i added (previ*(n-i+1) ) because segments starting at previ or before will work

how is the editorial doing (i−previ+1)(n−i+1) ?

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

Was there any $$$O(n)$$$ solution for F?

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

Figured out the cyclicity in problem E but couldn't manage edgecases properly :( . Good contest nonetheless

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

my first contest. I felt happy doing it, nice math problem of Collatz Conjecture btw.

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

Will be added after open hacks

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

F in O(n) using dp and next greater element using monostack. this soln works because sum of nge[i] — i over all i is bound by n:

vector<int> next_greater(vector<int> &a)
{
    int const n = a.size();
    vector<int> nge(n, n);
 
    stack<int> st;
    for (int i = 0; i <= n - 1; i++) {
        while (st.size() && a[st.top()] < a[i]) {
            nge[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
 
    return nge;
}
 
void pmi(int n)
{
    vector<int> a(n), b(n);
    for (int &ai : a) cin>>ai;
    for (int &bi : b) cin>>bi;
 
    vector<long long> dp(n + 1);
    vector<int> nge = next_greater(a);
    
    long long res = 0;
    for (int i = n - 1; i >= 0; i--) {
        long long cnt = 0, sum = 0;
        for (int j = i + 1; j <= nge[i] - 1; j++) {
            if (b[j] <= a[i]) {
                cnt++;
                sum += j;
            }
        }
 
        long long x = cnt * n - sum;
        long long y = (a[i] == b[i]) * (n - i);
        
        dp[i] = x + y + dp[nge[i]];
        res += dp[i];
    }
 
    cout<<res<<'\n';
}
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone tell me what is the correct answer of these testcases for problem E.
6 2
4 4 0 3 2 5
and
6 3
4 4 0 3 2 5

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

2137E and P10032 are exactly the same problem. Uh oh……

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

in problem F "If xi>yi, then there must exist an index jxi (as this guarantees ai to not be a prefix maximum)."

can some one explain this? why not xj >= xi

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

i think D is most easiest in the hard problems

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

Can anyone find the error in my submission for E

Getting WA on test 17

Submission

Idea was to simulate the mex operations for 6 times and then check with the oscillations

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

What was TC 17 added for , can someone tell :( , my solution failed it, and I cant figure out why

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

I registered for the problem as a rated participant but,currently I am been shown as an unrated participant. Is this a bug , how to appeal for the same. https://ibb.co/7txmfc86 https://ibb.co/RTSHrb4w

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

Proof_by_QED Can you please add the codes ?

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

In the solution for E, I believe it should say "If $$$x_i \gt y_i$$$, then there must exist an index $$$j \lt i$$$ such that $$$x_j \geq x_i$$$" (instead of $$$x_j \gt x_i$$$) since if a number is equal to the max seen earlier in its respective prefix, adjusting the value won't affect the prefix max. A small detail but could result in though I imagine it would result Wrong Answer.

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

Why does my solution to D keep getting Time Limit Exceeded?

It's basically the same as the editorial and runs instantly on my laptop???

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

Can someone help me understand why is this submission not working correctly?

I tried to stress test with 1000 test cases against the editorial solution and my solution, this still passed.

https://mirror.codeforces.com/contest/2137/submission/337554368

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

In problem D , it should have been specified that f is a one to one function as F(ai) = bi can't be true for 2 different ai. The problem gets much harder to solve if F is not one to one, so this should be noted.

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

Hello, I recently received a plagiarism warning for my submission (ID: 337404563) in problem 2137G. I want to clarify that I did not share my code with anyone nor did I intentionally copy from others. It is possible that the similarity occurred because:

  • The problem has a standard/common approach, so multiple solutions may naturally look similar.
  • My code might have accidentally become accessible (e.g., if I uploaded it somewhere with public access).

I respect the rules of Codeforces and contests, and I will ensure more caution in the future by:

  • Not uploading my code publicly during or immediately after contests.
  • Keeping my submissions private.

I kindly request you to review my case. I assure you that I did not intend to violate any rules.

Thank you for your understanding.

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

Hello Sir, I received a notification about my submission for problem 2137C coinciding with other solutions. I would like to clarify that I wrote my solution independently during the contest and did not copy it from anyone, I don't even know him.

It seems that the similarity may be due to the nature of the problem and the standard approach (many participants may arrive at similar implementations). I did not share my code with anyone, nor did I use any external/public source during the contest.

I kindly request the coordinators to review my case.

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

Hi, I got a plagiarism warning for submission [337362244]. I want to be clear that I solved this on my own — I don’t know any of the people you listed.

My first attempt was a divisor brute force (which TLE’d), then I realized it only boils down to a few cases and rewrote it. Because of how the problem is set up, there aren’t many different ways to write the optimized solution, so it’s natural that a lot of people’s codes (and even the official solution) look very similar. Even the solution you gave in editor is pretty similar just language is different

I never shared my code anywhere and definitely didn’t copy from anyone. So this plagiarism warning doesn’t make sense. Please reconsider.

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

Hello,I received a plagiarism warning for problem 2137D (submission 337440221).

I would like to clarify that about one week before the contest, my university lecturer explained a very similar exercise in class.

During the contest, I strictly followed the Codeforces rules — I did not share my code, I did not communicate with anyone, and I did not copy from any other participant.

It is possible that my solution looked very similar because I applied the same idea I had learned from my teacher, and also because I used a code formatter different from the one I usually use, which made my code structure look closer to others.

In the future, I will avoid reusing approaches I directly learned in class and will try to develop my own variations, so that such coincidences will not happen again.

Thank you for your understanding.

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

Hi Proof_by_QED

Relate to the problem 2137B - Fun Permutation, I think array, with value is equal to p_arr[i] = (n - arr[i]) if (n - arr[i]) else n, is also a correct permutation array.

Because, for every each i in range (0, n), p_arr[i] + arr[i] is either equal to n or 2*n, then GCD = n. Beside that, every element in p_arr >= 1 and <= n, then it's the permutation of n.

However, I summitted this solution to this problem, the result was wrong answer. Could you please help me to check this problem.

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

Hello everyone, I am just getting started on CodeForces. Could someone kindly explain which algorithm gives the exact output given for the sample input for the problem B — fun permutations? Thanks in advance.

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

Can anyone help me with problem E? I always get the 53rd answer in test 2 wrong but I can't see it Here's my code:

339058944

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

the code for F is wrong at one part.. ifykyk.. fix it and submit it in pypy.. then only it is accepted.. hope this helps someone..

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

the practice session was long maybe...

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

Proof_by_QED small errata: in your solution for for problem F when a[i] == b[i], you should do sol += (i + 1) * (n - i) instead of sol += (n * n + n) // 2. Your original code can't even pass the sample test.

You also mentioned:

This can be done in a variety of data structures. I used a set, but it is possible to use a segment tree or a stack as well.

But your solution uses a sparse stable instead of a set. I'm also skeptical about using a stack to solve this problem since you can't use stack to pre-calculate the right most $$$x[j]$$$ such that $$$j \lt i$$$ and $$$x[j] \gt = y[i]$$$. If using a set/stack is viable, how could they solve the problem?

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

    here my code AC using set<pair<ll,ll>>

    void solve() {
      int n; cin >> n; 
      vi a(n); forn(i,n) cin >> a[i]; 
      vi b(n); forn(i,n) cin >> b[i]; 
    
      set<ii> st; 
      ll tot = 0; 
      forn(i,n) {
        ll mx = max(a[i], b[i]); 
        auto it = st.upper_bound({mx,-1});
        ll frees = -1; 
        if (it != st.end()) frees = it->ss; 
        if (a[i] == b[i]) frees = i; 
        if (frees > -1) tot += (frees+1)*(n-i); 
    
        while (SZ(st) and st.begin()->ff <= a[i]) st.erase(st.begin());
        st.insert({a[i], i}); 
      }
    
      cout << tot << '\n'; 
    }
    
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Got lots of challenges for my math in this set of questions. Thanks

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

impressive

»
6 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The solution code of F is wrong it should be (i+1)*(n-i) instead of n*(n+1)/2.Proof_by_QED

369876707