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

Автор SlavicG, история, 23 месяца назад, По-английски

Thank you for participating!

1676A - Lucky?

Idea: mesanu and SlavicG

Tutorial
Solution

1676B - Equal Candies

Idea: Errichto

Tutorial
Solution

1676C - Most Similar Words

Idea: MikeMirzayanov

Tutorial
Solution

1676D - X-Sum

Idea: mesanu

Tutorial
Solution

1676E - Eating Queries

Idea: mesanu

Tutorial
Solution

1676F - Longest Strike

Idea: MikeMirzayanov

Tutorial
Solution

1676G - White-Black Balanced Subtrees

Idea: MikeMirzayanov

Tutorial
Solution

1676H1 - Maximum Crossings (Easy Version)

Idea: flamestorm

Tutorial
Solution

1676H2 - Maximum Crossings (Hard Version)

Idea: flamestorm

Tutorial
Solution
Разбор задач Codeforces Round 790 (Div. 4)
  • Проголосовать: нравится
  • +131
  • Проголосовать: не нравится

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится +25 Проголосовать: не нравится

It was honor to test this contest.Thanks for the Great round.Also great blog thanks for helping the community.

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

Thanks for the effort, much appreciated!

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

I had another solution for 1676G - White-Black Balanced Subtrees — I used DFS to recursively compute all vertices' values, saved them in an array and then just scanning the array for the vertices that have the equal number of white and black vertices in their subtrees. Maybe this is an easier explanation not containing DP clearly.

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

    This approach is DP as well as you are finding and storing all the values for black and white vertices for each subtree and then later only just iterating over all vertices to check which have equal no. of white and black vertices in their subtree. Actually it is quite similar to what is being done in the editorial as well except the fact that they are just finding number of balanced subtrees while doing dfs only and you are just running a separate loop after the dfs.

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

I really threw on C and D cuz I'm bad at determining time complexity.

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

    The same with D

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

      For C, I calculated the number of operations as (100 * 50 * 8)^2 instead of (50 * 8)^2 * 100. For D, I assumed that the intended solution was actually O(n^2)

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

my first unrated round and I have solved all of the problem in the contest time. happy coding :) problems were so interesting.

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

    wow..i saw ur profile if ur rating was just 12 less, your rating would go like a slingshot , just a little back,,,and so much further.

»
23 месяца назад, # |
  Проголосовать: нравится -16 Проголосовать: не нравится

The Time complexity of Problem D O(qlogn+n). But If we calculate for the worst-case according to given constraints then it should be -: 10^7 * 10^3 + 10^7. Also you are not considering the loop for test cases, so according to me its T.C should be. O(T*N*qlogN) However this T.C also not fast. So I am getting this doubt. Please correct me if I am wrong.

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

    I guess you are talking about problem E but not D.

    It is guaranteed $$$\sum n$$$ and $$$\sum q$$$ over all test cases don't exceed $$$1.5\times10^5$$$, so there's no need to multiply $$$T$$$ when calculating the time complexity.

    On this condition, the time complexity is $$$O(q\log n)\approx 1.5\times 10^5\times 17 = 2.6\times 10^6$$$, it's able to pass easily under the 3.5 seconds time limit.

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

Great Round, I am really excited to see my new cyan color.

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

E, F and H2 are really good problems.

Nice Div. 4!

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

problem h2 : Has anyone used ordered_set (multiset using pair) (pbds) ??

»
23 месяца назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Can someone please help me to understand the ordered_set solution to problem H2? I understand that "order_of_key(k)" returns the number of elements strictly less than k. However, I have seen many solutions that use an ordered_set with a pair to find the number of elements i<j && a[i] >= a[j], like this one:

ordered_set<ll>st;
    for(i = n;i>0;i--)
    {
        ans+=(st.order_of_key({a[i], inf}));
        st.insert({a[i],i});
    }
    cout<<ans<<"\n";

Why does order_of_key(a[i]) not work(to me, it seems that the index is irrelevant), and what is the functionality of pairs in an ordered_set? Any help would be appreciated.

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

    To what I can understand, people use pairs so that they do not have to worry about equal values. Since we need to find inversion that might be equal, it is a good idea to use pair<int,int> where every value had its unique index and we can get out answers simply by using order_of_key function call. You can also do this without using pairs, just use greater_equal<int> in your ordered_set typedef and use a map to store equal values.

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

I loved the round! The problems all had short and clean implementations, and I had a good take taking the contest.

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

thanks a lot for the round. It was great. hope to have many more Div4 rounds like this.

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

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

Can someone please explain how the BIT approach works for H2? Or maybe redirect me to some article which explains it well. Thanks.

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

Editorial solution for F in python TLE's

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

Hi, can someone explain why my nlogn solution failed for problem F. It got accepted during the contest and even after the hacking phase finished it was accepted. But now when I checked (14 hours) after the contest it suddenly got TLE on 18th test case.

  • »
    »
    23 месяца назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    It's because after the hacking phase is over all the solution are again tested with the test case used in hacks and so is yours, the main reason the worst time complexity is not nlogn it n^2, because the c++ unordered map uses linear data structure in case of collision to search for the elements , ideally it should be nlogn if instead of linear data structure, AVL tree is used which is the case with Java

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

      Thank you for the explanation. So is it not suggested to use unordered_map? I usually avoid using ordered map for better time complexity, but if unordered_map is not consistent, should I just stick with ordered map or any other alternative?

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

        Try to avoid them as much as you can but use ordered map always if Time complexity allows

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

Can someone please tell me why its giving tle its very similar to whats given in tutorial here is my submission https://codeforces.com/contest/1676/submission/156791528

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

    You are getting TLE because rather than iterating over the n values in the array your loop is iterating over all values in mini to maxi which can be very large of the range 10^9 as it is given in the constraints that 1 <= a[i] <= 10^9

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

If you use python and get TLE in problem F, I suggest you read this blog.

https://codeforces.com/blog/entry/101817

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

Can someone explain F? I got confused during the contest.

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

    you have to output a range L, R

    such that every element between L, R has count greater than equal to k, if there is no element in array its count is considered zero

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

orz

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

Can somebody help me with my Solution for question F. It got accepted last night during the contest but it was rejected in the system checking stating that it is giving TLE for Test case 18. My Solution for F

I am basically doing exactly what is mentioned in the editorial but mine is getting TLE.

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

I have experienced some shocking results in F problem where if I use unordered_map it gives me TLE but on using map its working fine! Am I missing something?

  • »
    »
    23 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

    When the value of n is large (usually larger than 10^5) then because there can be high number of collisions so hashmaps gives its worst case time complexity for insertion operations that is O(n) and not O(1) which is why the overall time complexity becomes O(n^2).

    The solution is to use a map as there we don't have a problem of collisions and the time complexity is logn per operation.

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

Please can you tell me what my submission giving TLE ?

Submission

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

Hi mesanu, for D. X-Sum my python code got TLE. I looked up the editorial, it looked similar to mine. Is it a language problem (like I have to use C++ rather than python) or I am missing something in my code?

My submission Id: 156738601

Thanks!

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

    You don't have to use c++. Try submitting in pypy 3, it is way faster.

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

The time complexity of F is not O(n) as mentioned in the solution, its O(n * log(n)) since we need to sort the array.

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

The g question why java is used in the tle code as follows https://codeforces.com/contest/1676/submission/156893634

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

in ques D, why you did num-=ar[i][j]*3

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

    cause you count it 4 times in 4 ( top right, top left, bottom left, bottom right ) diagonals.

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

Segment Tree for div4 round???????

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

Still getting TLE in Problem E even after applying lower bound binary search. Solution: https://codeforces.com/contest/1676/submission/159866893

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

    You are sorting array and calculating sums in each query. That is the reason you are getting TLE. You can do that before first query, since those values will be same every query. See my submission.

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

For F, finding the longest subarray of the good values array takes O(n) time. However, we must sort the array in advance which will be a O(nlogn) operation. I think that the overall time complexity should be O(nlogn) instead of O(n). Correct me if I am wrong.

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

A thing to point out: There was no need to sort the array in H2 again. It was already sorted by Merge Sort.

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

consider this comment is deleted