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

Автор Proof_by_QED, история, 8 месяцев назад, По-английски
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!
Разбор задач Codeforces Round 1047 (Div. 3)
  • Проголосовать: нравится
  • +67
  • Проголосовать: не нравится

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

speedy

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +32 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +2 Проголосовать: не нравится

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 месяцев назад, скрыть # |
Rev. 10  
Проголосовать: нравится +3 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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

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

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

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

Will be added after open hacks

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i think D is most easiest in the hard problems

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Proof_by_QED Can you please add the codes ?

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

the practice session was long maybe...

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

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 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

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

impressive

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

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

369876707