Leftist_G's blog

By Leftist_G, 2 months ago, In English

Thank you for participating and accompanying Simons! We hope you enjoyed the problems.

Rate the contest!
Rate the difficulty!
Rating Predictions

2205A — Simons and Making It Beautiful

Rate the problem!

Author: StayAlone

Solution: StayAlone

Hint 1
Hint 2
Tutorial
Code (C++)

2205B — Simons and Cakes for Success

Rate the problem!

Author: Leftist_G

Solution: Leftist_G

Hint 1
Hint 2
Tutorial
Code (C++)
Code (Python)

2205C — Simons and Posting Blogs

Rate the problem!

Author: Leftist_G

Solution: Leftist_G

Hint 1
Hint 2
Tutorial
Code (C++)

2205D — Simons and Beating Peaks

Rate the problem!

Author: cool_milo

Solution: cool_milo, Leftist_G

Hint 1
Hint 2
Hint 3
Hint 4
Tutorial
Code (C++)

2205E — Simons and Dividing the Rhythm

Rate the problem!

Author: Leftist_G

Solution: Leftist_G

Hint 1
Hint 2
Hint 3
Tutorial
Code (C++)

2205F — Simons and Reconstructing His Roads

Rate the problem!

Author: cool_milo, Leftist_G

Solution: cool_milo, StayAlone

Hint 1
Hint 2
Tutorial
Code (C++)

2205G — Simons and Diophantus Equation

Rate the problem!

Author: Leftist_G

Solution: cool_milo, LiHn, liuhangxin, Leftist_G

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Hint 7
Hint 8
Tutorial
Code (C++)
  • Vote: I like it
  • +110
  • Vote: I do not like it

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

Maybe my skill issue but C killed my back implemented D and got short just 1 minute :(

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

Hello,I‘m the provider of D and F,and I also helped with some G issues :D, thanks again for everyone who participated in this round! Please rate the problems carefully >_<

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

I have a nice solution to D, and I didn't completely get the editorial one so I will write it.

let's observe that in the end the array is decreasing and then increasing so let's see what happens if i is the index of the turning point.

I claim that I keep the indices of the monotonic stack when it's get to i, both from the left and right side, the dec monotonic.

why is that true you ask?

well let's call the next one bigger than i from the right j, such that of course j>i lets say that j is not in the final array, therefore I popped it with something bigger than it, this can go on but the point is there is an element in the final array which is bigger than the value in index j, so therefore I can just bring j back, there isn't something between i and j that is bigger and everything which is between j and the one which is bigger than him have to have been popped because j is gone so on for every index of course and the left side

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

I did so much extra work with A (cry). Could've saved some time there if I could've thought straight, but it is what it is.

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

This is the first time the DBOI team has prepared a contest on Codeforces — and probably the last. We spared no effort, and preparing this contest really took a lot of time. The contest would not have been possible without everyone’s help, including those who contributed problems (even the rejected ones), helped with testing, and of course our coordinator.

Hope you enjoy the contest, and we truly appreciate your advice and feedback.

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

    why "probably last"?

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

      StayAlone and I need to prepare for the 2027 College Entrance Exam in China, and cool_milo will prepare for his graduation at Tsinghua University at that time, which is also hard work.

      We have worked for the round diligently for months, so we may not have the same dedication and energy to prepare for rounds like this in the future.

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

Hi, I believe Task D is similar to a standard CSES task i.e. Mountain Ranges.

It can be solved via Dynamic Programming + Monotonic Stack/Range Query Data Structures too!

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

    Recurrence is similar. I have previously solved Mountain ranges and thus got a deja vu feeling while solving today's D. But the main part is to deduce that we need to find the longest V shape in the array.

    I think it's a good enough manoeuvre to appear in a rated round.

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

      True! I do agree the task is nice, especially the fact that once one observes that there can be only one valley (or an upward/downward slope), it's essentially maximising it's length (and subsequently minimising number of operations).

      The Mountain Ranges reference hit me because it felt oddly related, overall a decent task for sure!

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

      By longest V you mean longest decreasing subsequence ending at i + longest increasing subsequence starting at i right? Or am I missing something?

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

        yes

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

          but if you have something like 7 6 5 15 4 3 ..... then for 3 seeing towards left,i have to consider only 15 4 3 (what stack gives) lds ending at 3 gives 7 6 5 4 3 which is not allowed because we have to take the maximums ?

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

fun fact about F: every planar graph has a dual, and some graph theoretic properties in the primal graph become other graph theoretic properties on the dual graph. for example, an Eulerian subgraph (all degrees are even) in the primal corresponds exactly to a cut (coloring the faces 0/1) in the dual. it turns out that thinking about the dual graph in this problem makes the weird alternating sum formula and the connectivity constraints a lot more intuitive (at least for me).

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

D can be solved using a stack+dp too!!

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

I have an alternate and possibly easier solution for D. For array to be cool, note that it has a fixed minimum element and the array is decreasing before that and increasing after that.

Fix the index of the minimum element (i) and now think how will the array look. Focus only on the subarray left of i. Note that the maximum element ( call its index l) in this range will be the first element of the final array. With some thought, it can be seen that the next element in the final array will be the maximum element in the range (l,i) and so on... . Same thought can be applied to the array at the right of i. The implementation turns out to be easy.

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

Congratulations to the setters for a flawless round ! Here is my opinion about each problem:

A
B
C
D
E
F
»
2 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Another (probably) unintended solution for D: Go through the elements x in increasing order. If one of the neighboouring elements is bigger, we are done with x its cost is 0. Otherwise, you need to remove all elements adjacent to x on one side untill you reach a bigger element. It is optimal to take the direction with the minimal number of removed elements minus the sum of their costs, so whenever our final array contains x we know which direction to go to. We can then set the cost of these removed elements to 0, and set the cost of x to the number of removed elements, since every valid array containing those smaller elements would also contain x, but then it would be optimal to delete them so x has a bigger neighbour. Our total cost is the sum of the elements of the array. TO get the sum of a segment and set all elements in a segment to 0, we use a lazy segment tree.

Implementation: https://mirror.codeforces.com/contest/2205/submission/364533929

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

shouldn't something like this be possible in problem F? (i'm assuming i misread/misunderstood the problem)

(the number adjacent is the degree)

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

    It is possible, and it can be represented with one basis for each of the four outside squares (no basis for the inside square, as that would cancel out the inner edges).

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

      i see, so i accidentally turned the problem into a different (and miles harder) problem

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

C was tough!

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

Problem C can also be solved using pointers.
Implementation : 364562915

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

Really nice contest. Tried solving C first. Got cooked :(

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

Not bad CN, it breaks my bad impression of CN.

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

C>>D imo. Spent ~30 mins on thinking about a greedy of C but used only ~3 mins to come up with a solution of D(The spent only 4 mins on it).

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

Cannot believe B has so many AC. Thanks for the contest though.

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

Check out my submission for G: https://mirror.codeforces.com/contest/2205/submission/364629640

It is quite a bit shorter than the editorial code. I also did inclusion-exclusion in a bit of a weird way: we only want to subtract $$$d$$$ such that $$$d$$$ does not divide $$$n$$$. Hence we can skip $$$d$$$ such that there is a $$$p | n$$$ such that $$$p^e$$$ divides $$$d$$$ but $$$p^e$$$ does not divide $$$n$$$ for some $$$e \gt 1$$$. (you can figure this out without factoring $$$n$$$!). Then we multiply by $$$\mu\left(\frac{d}{\gcd(d,n)}\right)$$$. So you can get away with not computing some $$$f(T)$$$, where either T fails the above checks, or $$$\mu\left(\frac{T}{\gcd(T,n)}\right) = 0$$$, although this is only a constant optimization.

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

Why does my $$$O(n^3)$$$ solution pass for C?

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

Sharing a very USER-FRIENDLY solution of C

http://mirror.codeforces.com/contest/2205/submission/364637515

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

In problem G, how to show the complexity of "naively save the intervals, sort them, and then apply two pointers" method is $$$O(m \log ^2 m \log \log m)$$$ ?

I also read jiangly's code (364548110) and I believe he used this method. Maybe I misunderstood the process of this method?

My approach on the complexity
  • »
    »
    2 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +5 Vote: I do not like it

    I submitted liuhangxin's testing code at here. I considered and analysed his code for the conclusion that the complexity of the method is $$$\mathcal O(m\ln m\log m\log\log m)$$$.

    I think the process is, for both $$$d_1T$$$ and $$$d_2T$$$, valid $$$j$$$-s distribute in $$$\mathcal O(\log m)$$$ uncrossed intervals, and we just need to calculate the number of $$$j$$$-s covered by two intervals. I think that if we sort the two sets of intervals independently, this can be completed using two pointers in linear complexity. Thus, the whole complexity is $$$\mathcal O(m\ln m\log m\log\log m)$$$.

    I guess liuhangxin's method is a "symmetrical" method with jiangly's, according to your description. Could you please try understanding the method above?

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

      I think liuhangxin's testing code actually used some non-trivial ways to sort the intervals. This code first sorted all $$$dT\ \mathrm{xor} \ m$$$ and then directly construct the list of sorted interval endpoints (which will be stored in tmp) using function void get(int l,int r,int d). And I believe this code is $$$O(m \ln m \log m)$$$ time, as the construction actually runs in the same logic as the solution using trie.

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

        Also, I believe jiangly's code is a different approach compare to this one.

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

          Thanks for your thinking. I will remove the "$$$\log\log m$$$" from the complexity described in the solution.

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

can anyone tell me what is wrong in my solution for problem C : 364542311

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

    You have this check

    if(curr.size() == 0 ...)
    

    which i guess assumes something like first iteration throughout the cycle. But the size of this array can be zero not only on first iteration.

    Here the same code accepted with only this place changed 365052100

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

      Thanks for pointing out, I found that just after commenting, sad that i couldn't understand this during the contest.

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

For C my code does work but I have strong intuition that its O(n^3 * log(n)) that shouldn't pass can someone help me figure out what's happening

Here is my code: ~~~~~~

include <bits/stdc++.h>

using namespace std;

void solve() { int n ; cin>>n; vector<vector> v(n); for (int i = 0; i < n; i++) { int l ; cin>>l; vector temp(l); for (int j = 0; j < l; j++) { cin>>temp[j]; } reverse(temp.begin(), temp.end());

map<int, int> local_seen;
    for (int x : temp) {
        if (!local_seen[x]) {
            v[i].push_back(x);
            local_seen[x] = 1;
        }
    }
}

sort(v.begin(), v.end());

map<int, int> visi;
for (int i = 0; i < n; i++) {
    for (int j=0 ; j<v[i].size(); j++) {
        if (!visi[v[i][j]]) {
            cout << v[i][j] << " ";
            visi[v[i][j]] = 1;
        }

    }
    for (int j = i+1 ; j<v.size(); j++) {
        vector<int> current; map<int,int> seen;
        for (int x = 0; x<v[j].size(); x++) {
            if (visi[v[j][x]] || seen[v[j][x]]) {
                continue;
            } else {
                current.push_back(v[j][x]); 
                seen[v[j][x]] = 1;
            }
        }
        v[j] = current;
    }
    sort(v.begin() + i+1 , v.end());
}
cout<<endl;

}

int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }

~~~~~~

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

what does It's noticed that the maximum number of each number cannot be moved even mean in the problem D tutorial?