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

Автор dope, 16 месяцев назад, перевод, По-русски

Спасибо за участие в раунде! Надеемся, что задачи вам понравились!

2057A - Таблица MEX

Автор и разработчик dope

Решение
Реализация

2057B - Горилла и зачет

Автор и разработчик dope

Решение
Реализация

2057C - Поездка на олимпиаду

Автор teraqqq, а разработчик dope

Решение
Реализация

2057D - Заказ мерча

Автор и разработчик dope, также спасибо mupp и KoT_OsKaR за обсуждение со мной этой задачи

Решение
Реализация

2057E1 - Очередное упражнение на графы (простая версия)

Автор teraqqq, разработчик dope

Решение
Реализация

2057E2 - Очередное упражнение на графы (сложная версия)

Автор teraqqq, а разработчик dope

Решение
Реализация

2057F - Линейка

Автор induk_v_tsiane, а разработчик dope

Решение
Реализация
Алтернативное решение

2057G - Секретное сообщение

Автор и разработчик teraqqq

Решение
Реализация

2057H - Перерыв и кофемашины

Автор и разработчик teraqqq, спасибо FairyWinx за оказанное вдохновление

Решение
Реализация
Разбор задач Hello 2025
  • Проголосовать: нравится
  • +61
  • Проголосовать: не нравится

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

first

C and D were cool imo

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

It looks like b has some typographical errors :)

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

thank you for opening the new year!

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

Can anyone help me find out the cause of the difference of these submissions? 299626640 299629236

I'm pretty sure the codes are exactly the same, and on my local MSVC the outputs for the examples are also correct (same as C++23). I don't recognize any UB in my code, so I don't get why C++20 shows a wrong output while C++23 runs as my expectation.

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

    Fascinating.

    I was able to simplify this down to something like the following (run in customtest under G++20 13.2, 64 bit)

    #include<iostream>
    
    int main()
    {
    	int l, r;
    	std::cin >> l >> r;
    //	l = 128, r = 132;
    	for (int i = 30; i >= 0; i--)
    	{
    		if (!!(l & (1 << i)) != !!(r & (1 << i)))
    		{
    		      std::cout << i << '\n';
    		      return 0;
    		}
    		if (l & (1 << i)) return 0;
    	}
    }
    

    This outputs 7 when 128 and 132 are given as input, and quits quietly if the line // l = 128, r = 132 is uncommented. Haven't seen anything like this before. It seems I should recall something from the very beginning of my journey, where someone once mentioned to me that bitwise operations with signed integers can lead to UB. However, I couldn't find any information about this online.

    It would be very interesting to hear from someone more experienced in C++ about this issue.

    UPD: Looks like this is a compiler bug. I shared the problem in a local chat, and they showed me the site. The file about C++ 20, parts 7.6.7 and 7.6.11 seem to define correctly bitwise operations both for signed and unsigned integers .

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

      Wow, so I guess it's high time that I completely move on to C++23. Thank you for the analysis.

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

      I found out something interesting :D

      #include<iostream>
      
      int main()
      {
      	int l, r;
      	std::cin >> l >> r;
      // 	l = 128, r = 132;
      
      	for (int i = 30; i >= 0; i--)
      	{
      	    
      	     int res = (!!(l & (1 << i)) != !!(r & (1 << i)));
      	     if (res > 0)
      	     {
      		  std::cout << res << " res\n";
      		  std::cout << i << "\n";
      		  return 0;
      	     }
      	     if (l & (1 << i)) return 0;
      	}
      	
      	return 0;
      }
      

      Output on G++20 13.2, 64 bit:

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

    Compiling with #pragma GCC optimize("O0") seems to fix this bug

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

I misread problem C and thought I had to maximize a ⊕ b ⊕ c. Anyone knows a solution to this problem instead of the original one?

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

I have been practicing questions from various sheets (CP-31 mostly) got recently introduced to themeCP.

i can solve 800-900 rated questions with little effort but 1000 rated problems do take up my time.

Can someone lend some resources that might help?

My problem -> I thought Solution of A at an instant but took time trying to prove myself that it will actually work (drawing various scenarios). Same happened with B.

Thanks in Advance for advices :)

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

Nice round. Thank you for the wonderful problems.

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

D should not be a segment tree, solving D in a 2.5hr contest with such easy ABC is the level of high specialist/low expert, and many people at this level don't know segment tree, or they know it at a basic level and don't have enough experience/understanding to solve this kind of segment tree problems where they require a not-so-obvious merging. the problems were good and were at the standard of a Big div1+2 contest, but the fact that D required segment tree and no other solutions existed in such an important contest is disappointing.

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

C was a very good problem. Thank you.

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

I learnt two things from this contest:

  1. I can figure out the logic/pseudocode for the question in ~10% of the time I spend on the problem when it should be the opposite. I struggle with writing the code for it.

  2. I suck at bitwise operations. Does anyone here have a good list of questions to practice to get good at basic problems (upto C level?)

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

C also can be solved by Ternary Search

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

    Could you explain your approach please :D.

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

      Yeah if you know two things

      First.You know how Ternary Search works?

      Second.Do you know that there is always a triple of numbers l,r and some c where l and r are given numbers?

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

        After watching a 4 min YouTube video, my current understanding is that Ternary search is similar to binary search except that we have two mid values in the search.

        As for your second point, I tried making a=r and b=l in the contest, and I kinda "guessed" that there must be a third value that would maximize the pairwise xor sum, and I thought of the 1's complement (starting from the MSB 1 bit of r), and it turned out to give the same pairwise xor sum as in the input example, except that I got values less that L sometimes, and I couldn't think of a better way.

        Forgive me for making a long comment.

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

at problem c you can choose a as being l , b as being r ,and c as being the value that maximizes the sum , so to calculate c you go decreasingly on bits and if the bits are present in both l and r you have to take it,if it's present in l we have to take it and if its not presesnt in l we just see what would happen if we took this bit and then choose the other smaller one greedily,overall complexity(30^2)

»
16 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится +6 Проголосовать: не нравится

I cheesed C with a randomization algorithm.

It passed systests.

Please hack it.

https://mirror.codeforces.com/contest/2057/submission/299661239

V2: https://mirror.codeforces.com/contest/2057/submission/299698846

UPD: Hacked by MattTheNub

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

For E you can forget the binary search altogether by processing queries offline.

For a query (i, j, k), everytime you change the distance d(i, j), check if d(i, j) < k, and the first time this happens, the answer to that query is the value of the edge you're adding.

By storing the lists of queries for each (i, j) sorted by k, you can process all these simply as you modify the graph, and you don't have to store the dp layers.

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

can so explain why my submission(problem b) is wrong?

https://mirror.codeforces.com/contest/2057/submission/299644013

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

Several python solutions from I've seen (including mine) for problem B have TLE'd on test case 17. What is the cause of this?

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

Hmmm, IDK why I approached D the way I did, segment tree would've been much simpler and faster especially since I used the same logic for my solution.

However, it's weird that $$$O(n * \sqrt{n})$$$ struggled to pass. In the end, it squeezed in just enough to pass when I changed the block size from $$$\sqrt{n}$$$ to $$$550$$$ which is also weird. Any ideas?

Here's the submission 299683723

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

can anybody tell why it is giving TLE?(B problem) https://mirror.codeforces.com/contest/2057/submission/299631565

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

https://mirror.codeforces.com/contest/2057/submission/299695552

For b this shud work ryt it's just nlogn but tle for testcase 14

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

Solution code for D doesn't match the editorial. Editorial says that it's enough to store answer, minimum and maximum of $$$a_i - i$$$, but in the solution there are some $$$max1, max2, min1, min2$$$ stored in the node

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

    If you observe carefully, we can create 2 separate test cases to be solved:

    1. In the range (l, r), al is the minimum element, and ar is the maximum element. This can be solved by changing the array to: ai-i, and final answer be given as (ar-r)-(al-l).

    2. In the range (l, r), al is the maximum element, and ar is the minimum element. This can be solved by changing the array to ai+i, and final answer be given as (al+l)-(ar+r).

    This 2 cases can be modeled in separate segtrees, or storing the information in the same segtree.

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

      Yep, I've upsolved it already, just pointing out an incorrect editorial

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

      Can you explain how you implemented this? In particular, after you build the two segtrees, how do you query the answer? I think it's just querying the max difference between two elements where the max element appears after the min one (or vice versa), but not sure how to code this.

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

        I'll give you the logic for the 1st one, because both cases are just analogous of each other.

        For each node in the segtree representing the segment (l, r), I'll be storing 3 pieces of information for the changed array: min element (al...ar), max element (al...ar), answer for segment (l, r)

        Now I can simply merge 2 nodes, lets say left and right, as ans=max(ans_leftnode, ans_rightnode, max_rightnode-min_leftnode), max element=max(max_leftnode, max_rightnode), min element=min(min_leftnode, min_rightnode)

        To be exact this is your merge function:

        void merge(Node1 &l, Node1 &r) { // Merge two child nodes
        		maxval = max(l.maxval , r.maxval);
                        minval=min(l.minval, r.minval);
                        ans=max(max(l.ans, r.ans), -l.minval+r.maxval);
        	}
        

        You can check out my submission for a similar working of the other testcase: 299657175

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

Why using unordered_map in problem B gave TLE on testcase 14!!!!

Replacing it with map worked...

my solution passed prestests, but failed in system testing.. this is awful

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

    Because unordered_map is not implemented in the best way in C++.

    You can read more about that here

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

      thanks..

      I already found this amazing post and was reading it and it seems to work.

      Does it mean that we should always use map in cpp in competition?

      While using unordered_map with custom hash worked for problem B, it doesn't seem to be faster than the map implementation in any sense

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

        Solutions using default unordered_map in c++ generally get hacked because the hash function is fixed and specific test cases could be made in order to create lots of collisions which changes the find tc to O(n) from O(1). For a random custom hash, specific test cases for collisions can't be created.

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

In Python, I feel very comfortable, but I don't have the same ease with C++, and I’m not sure how to achieve it—I guess it’s just a matter of practice. This was my third contest, and I managed to solve the first two problems using Python. However, during the system testing, the second problem resulted in a time limit exceeded, even though my algorithm was correct :(. Any advice on transitioning to C++?

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

For E2, using DP and binary search is overcomplicated. We don't need to use either by processing the queries offline, resulting in much easier code.

https://mirror.codeforces.com/contest/2057/submission/299696265

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

About E1. Why is E1 in the set when the constraints are so tight that some intended complexity solutions don't pass? Mine was $$$O(n^3 logn)$$$ takes 5600ms in the mashup, 4200ms in C++20), which is fine not to pass, in my opinion. But some $$$O(n^3)$$$ solutions are not passing as well, for example (funnily enough, this passes on C++23). For me, this just led to spending a lot of time trying to optimize constants (an almost correct time complexity) instead of thinking about how to solve E2.

Also, the constraints were not even tight enough to kill bitset, so I am curious why $$$n = 400$$$ was chosen.

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

Got TLE for B with two approaches: 299696692 299635098 What could be wrong?

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

Sadly, nobody got 2025 rank in today's contest :( .

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

In the editorial for E1 it says

d′[i][j]=min{d[i][j],d[a][i]+d[b][i],d[b][i]+d[a][i],}

shouldnt it be d'[i][j]=min(d[i][j],d[a][i]+d[b][j],d[b][i]+d[a][j]}?

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

299701558

Hey, could anyone figure out why my solution TLEs? It runs in O(nlogn) time with the single sort, which is the same complexity as the solution.

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

I propose a solution for 3rd one.. it seems simpler to me.. please give your opinions -

  1. Take a = l, b = r.
  2. Find the 1st different bit in l and r.
  3. Then take complement of rest of part of l and r and store resulting number in cl and cr respectively.
  4. Now if cl < r, c = cl, Else if cl = r, c can be any number between l and r Else c is cr.
»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится -20 Проголосовать: не нравится

Wtf segment tree problem in D? It is bad

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

My code 299683214 passed on pretests and gave tle on final tests, and now it is again passing 299704642.

Can it be reviewed? teraqqq induk_v_tsiane dope

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

Can anyone help me figure out where I go wrong in my solution ? https://mirror.codeforces.com/contest/2057/submission/299683979 I basically try to maintain the maximum, the minimum, and their respective indexes, along with the value of a segment for max difference. The value becomes something like max(left value, right value, abs (left max — right min) — abs (l1-r1) , abs(left min — right max) — abs (l2-r2)) where li ri are indexes of the maximum and minimum

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

I had a different solution for E1/E2, maybe it is easier to understand for some people.

E1: For every query, check if each edge can be the answer. To do so efficiently, for every edge going from u to v with weight w, precompute the the arrays udist and vdist, where udist[x] equals minimum # of edges with weight >= w needed to go from u to x, and same for vdist[x]. This can be done with 2M djikstras, so complexity of precomutation is O(M^2 log N). Checking if an edge can be the answer can be done in O(1) by checking if udist[a] + vdist[b] < k or udist[b] + vdist[a] < k. Total complexity is O(M^2 log N + MQ). MQ part might be bad complexity but it is just some array lookups so very low constant factor. Submission: 299661500

E2: Same thing as E1 except observe that the edge of the answer must be on the MST. This means for every query you only need to check O(N) edges. You also only have to do the precomputation step for O(N) edges. Use djikstras on dense graphs (O(N^2 + M) = O(N^2)), so complexity of precomputation is O(N^3). Total complexity is O(N^3 + NQ). Submission: 299706362

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

    Look at this test for problem E1:

    1
    9 12 1
    1 2 100
    2 3 100
    4 5 100
    5 6 100
    1 4 100
    4 7 100
    2 5 100
    5 8 100
    3 6 100
    6 9 100
    7 8 1
    8 9 1
    1 3 3
    

    model solution prints "1" but answer and your soluton is "100". Am I wrong?

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

Look at this test for problem E1:

1
9 12 1
1 2 100
2 3 100
4 5 100
5 6 100
1 4 100
4 7 100
2 5 100
5 8 100
3 6 100
6 9 100
7 8 1
8 9 1
1 3 3

main and tourist prints "1" but answer is "100". Am I wrong?

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

    The input must guarantee that any path from vertex $$$a$$$ to vertex $$$b$$$ contains at least $$$k$$$ edges. In your case, the path $$$1 - 2 - 3$$$ contains only $$$2$$$ edges, which is less than $$$k$$$.

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

I'm curious about why my submissions got TLE:

E1: https://mirror.codeforces.com/contest/2057/submission/299716714 I also see one of my friend's submission, he wrote the same thing as me, but he got accepted. https://mirror.codeforces.com/contest/2057/submission/299642675

If it's because of my large constant, I don't think this is fair.

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

ABC were too easy, but D was an interesting segment tree problem

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

E2 can be solved in O(N^3) without the extra term of qlogN by precomputing answers to all possible queries on the go — https://mirror.codeforces.com/contest/2057/submission/299682395

This allows to answer any number of queries (say 5e7) in the given TL.

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

I think B is easier than A cuz it only requires implementation.

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

This Contest was Div1 or Div2? How do we get to know if a contest is div 1 or div2 if not mentioned in contest name?

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

In Problem B, using unordered_map passed the pretests but caused TLE on test 11. Switching to map resolved the issue, and the solution was accepted. Can someone explain why ?

submission with unordered_map : https://mirror.codeforces.com/submissions/phoenix_vasu# submission with map : https://mirror.codeforces.com/submissions/phoenix_vasu# The only difference between these 2 code is unordered_map and map

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

I solved D by finding maximum subarray sum on the difference array

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

    can you elaborate how you did it using difference array and why used difference array as such ?

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

      First, think a descending array. Since the first element is the maximum you need to take it and while you are taking the elements one by one by iterating to the right, the minimum will decrease as the difference, and since you took one new element the number of elements you have chosen will increase and your answer will decrease by 1. So, when you select a new element your answer increases by (difference-1).

      To generalize, when you select the subarray with maximum sum the left and right borders of it are the maximum and the minimum element in the optimal subarray.

      The maximum can be the left border and the right border so to cover it I found the maximum subarray sum in the difference array by subtracting 1 from every element, and I also found the maximum subarray sum by complementing its elements and subtracting 1 from them. We need to subtract 1 from the elements because when you select one more element you need to subtract 1 because the score is (maximum-minimum-number_of_elements) I think you may better understand by trying some cases on the paper. Please feel free if you have a question.

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

Why did the problem 2057B - Gorilla and the Exam I cannot use unordered_map, I got TLE when using using it

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

ML of G is too tight I think. The 2e6 data range and the 256 MB space literally made no sense.

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

Can anyone explain to me, why using "arr = [int(x) for x in input().split()]" instead of arr = input().split() results in execution time becoming more than 10 times slower.

299755424 --> slower one 299754131 --> faster one

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

there is a mistake in E1: $$$\textrm{d}'[i][j] = \min { \textrm{d}[i][j], \textrm{d}[a][i] + \textrm{d}[b][\not{i} \ j], \textrm{d}[b][i] + \textrm{d}[a][\not{i}\ j], }$$$

upd: it fixed

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

I have done Problem C with a idea that l and r can be contained in an answer,and after that I use dfs to find another integer,and it gets ac,could anyone please tell my why this ieda works well?

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

Has anyone Happy New Year! question D without segment tree? For example, with sqrt?

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

this is not allowed ,this user is hiding his submissions .

https://mirror.codeforces.com/contest/2057/submission/299609972

dope

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

During the round I got WA3 299664488. However my solution was failing due to OOB, and codeforces returned WA, instead of RTE, here is a fixed version 299794827. I was breaking my head for it :(.

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

For the solution code for D, what is the purpose of subtracting $$$n-1$$$ from the second value of the pair?

The code still gets accepted when I replace

t[i] = {a[i] - i, a[i] + i - n + 1};
...
t[p] = {x - p, x + p - n + 1};

with

t[i] = {a[i] - i, a[i] + i};
...
t[p] = {x - p, x + p};

Seems like an unnecessary operation, unless I'm missing something.

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

    It may be more intuitive for some people, as $$$x+p-n+1$$$ effectively means "take the reverse index of the position (that being $$$n-1-p$$$), and subtract from $$$x$$$, making this in some sense the same thing as $$$x-p$$$, just in reverse. It doesn't change the solution, as it's a constant change for each value in the array and you always take the difference of $$$2$$$ values in the array.

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

won't the E1's solution fail at the below testcase. It should be giving 11 as the answer but is giving 1.

9 9 1
1 2 11
2 3 12
3 4 13
1 5 14
5 6 15
6 7 16
7 8 1
8 9 17
9 4 18
1 4 4
  • »
    »
    16 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    The problem statement guarantees that for every query $$$(a, b, k)$$$, any path from $$$a$$$ to $$$b$$$ contains at least $$$k$$$ edges. In your given test case, this isn't satisfied: you have a query $$$(1, 4, 4)$$$, yet there is a path from $$$1$$$ to $$$4$$$ using only $$$3$$$ edges ($$$1-2-3-4$$$). Therefore, your given test case isn't valid.

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

why this code 299978985 is getting accepted but this one 299979242 is giving TLE although both are same. Thanks in advance.

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

In Question B when I use unordered_map to count the frequency it give tle on test case 14, but when I used map instead of that it worked fine.

any reason?

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

Doubt In E2:

Why we can't write if(dis[p-1][u][v]!=0) instead of if (dsu.merge(v, u)) ??

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

I know I am writing this comment too late .. but problem C came into my radar now! The problem is clearly dope in my opinion, how can someone come up with such a strategy? Are there any resources or theoretical knowledge required for solving it? The editorial solution is gold!!

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

is there any alternate solution to d(using some sort of data structures) that merge solution is so hard to implement -_-