Proof_by_QED's blog

By Proof_by_QED, history, 13 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

| Write comment?
»
13 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

speedy

»
13 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).

»
13 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.

»
13 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 :(

»
13 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.

»
13 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.

»
13 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

»
13 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.

»
13 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.

»
13 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://codeforces.me/contest/2137/submission/337457768

»
13 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

  • »
    »
    13 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.

»
13 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) ?

»
13 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';
}
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

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

i think D is most easiest in the hard problems

»
12 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

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

Proof_by_QED Can you please add the codes ?

»
12 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.

»
12 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://codeforces.me/contest/2137/submission/337554368

»
12 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.

»
12 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

»
12 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..

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

the practice session was long maybe...

»
11 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?

  • »
    »
    11 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'; 
    }
    
»
11 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

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

impressive

»
6 months 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