Vladosiya's blog

By Vladosiya, history, 21 month(s) ago, In English

2000A - Primary Task

Idea: ibraevdmitriy

Tutorial
Solution

2000B - Seating in a Bus

Idea: myav

Tutorial
Solution

2000C - Numeric String Template

Idea: myav

Tutorial
Solution

2000D - Right Left Wrong

Idea: Vladosiya

Tutorial
Solution

2000E - Photoshoot for Gorillas

Idea: Vladosiya

Tutorial
Solution

2000F - Color Rows and Columns

Idea: ibraevdmitriy

Tutorial
Solution

2000G - Call During the Journey

Idea: ibraevdmitriy

Tutorial
Solution

2000H - Ksyusha and the Loaded Set

Idea: ibraevdmitriy

Tutorial
Solution
  • Vote: I like it
  • +27
  • Vote: I do not like it

| Write comment?
»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone pls tell why this code is getting a runtime error. for Problem D

Code

And also the issue with the algo pls.

  • »
    »
    21 month(s) ago, hide # ^ |
    Rev. 2  
    Vote: I like it +3 Vote: I do not like it

    consider the case where there are no 'R' in the string. in this scenario, your 'right' variable would be initialized with the value -1

    edit : avoid using C++17 (GCC 7-32) and use C++20 (GCC 13-64) instead

    • »
      »
      »
      21 month(s) ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      you mean something like this -> n = 6, a(n) = 1 1 1 1 1 1 s = LLLLLL -> and the output should be 0 right. actually I checked this one already and it gives me 0 perfectly fine. Cause I'm checking the out of bound condition before using those

      • »
        »
        »
        »
        21 month(s) ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I admit I do not know much about C++17 (32-bit), but if I had to guess, this particular error might be occurring because your while loop condition:

        while(left < leftsig.size() && right >= 0 && leftsig[left] < rightsig[right]) {

        is not stopping after right >= 0 evaluates to false. Instead, it continues evaluating leftsig[left] < rightsig[right], which could cause an access violation if right is -1 and thus result in the error

        you can fix it by choosing C++20 (GCC 13-64) as your compiler when you submit the code

        https://mirror.codeforces.com/contest/2000/submission/276452095

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    This solution will give tle as you are calculating sum of subarray again and again. Instead use prefix sum to get the sum of the subarray.

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I need help

Can anyone tell me why my solution in proplem E got TLE when i write it in java , but when i write the same code in c++ i got AC

java solution --> Your text to link here...

c++ solution --> Your text to link here...

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

someone explain how to intuit the way they count it in problem E please.

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    do u know diffrence array? to update values in range for 1d vector it can be used here to count for 2d vector then 2d prefix sum

»
21 month(s) ago, hide # |
Rev. 3  
Vote: I like it +17 Vote: I do not like it

I am impressed by how treap is being casually used in a div3 contest editorial (problem H).

(Context: Of course I am well aware that this is not how most contestants solved, or are supposed to solve it, but rather make use of the (non-essential) constraints max <= 2e6. It is also clear that a fully online solution of this without the extra constraints will have to involve your favourite BBST. Though, I don't know how many people will get confused by the editorial. )

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it +33 Vote: I do not like it

    They took the effort to explain the std::set part but not the treap part :)

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    If possible can you explain how to do it without treap? I was thinking of a solution where I can maintain an array where the indices represent the lengths of the free segments and the value at that index is the value of the left border of that segment, then I just need to find suffix minimums to answer any query. I was thinking of using segment tree for handling updates and suffix range queries, but I think that will TL because there is no bound on sum of $$$max(a_i)$$$ across all test cases and my time complexity would become $$$O(T\cdot max(a_i) \cdot\log{max(a_i)})$$$ in that case.

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    treap sounds like something you cover a pool with

»
21 month(s) ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

for E, I completely missed the n*m<=2e5 bound and coded a O(nlogn + mlogm + wlog(n*m)) solution

276188663

  • »
    »
    21 month(s) ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    I also misread the n*m<=2e5 constraint, and I tried to code a bfs type solution starting from the center of the grid where we greedily visit cells in the graph that have the most subarrays containing them. I failed in the implementation, but is your solution idea similar?

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I got scared when I didn't see the n*m <= 2e5 condition and I immediately re-checked the problem statement :)

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

H can be solved using segment tree. 276462150

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How can I report suspected cheating in this round?

»
21 month(s) ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

The problem H has a beautiful solution using sqrt decomposition (It works slower than the author's solution, but it seems to me easier to understand and write). My example solution: https://mirror.codeforces.com/contest/2000/submission/276433907

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it +4 Vote: I do not like it

    Problem H Solution without any specific method/data structure but only logic — 276496494

    • »
      »
      »
      21 month(s) ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      what is the time complexity of this block?

      auto fitr = que.lower_bound(x);
                  if(fitr == que.end()) cout << -1 << " ";
                  else {
                      int mini = INT_MAX;
                      for(; fitr != que.end();) {
                          mini = min(mini, *(fitr->second.begin()));
                          fitr = next(fitr);
                      }
       
                      cout << mini << " ";
                  }
      
      • »
        »
        »
        »
        21 month(s) ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Worst case is ~ $$$\sqrt {2 . 10^6}$$$. When the set has 2e6-1, 2e6-4, 2e6-8, 2e6-13, .... and the query is "? 1" ig

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain me Problem F in detail? I saw shayan's vid but I keep getting lost. (I have a fair experience with dp)

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    The hardest part of this problem is understanding optimal way of painting single rectangle. Like they say in editorial you must always choose to paint single column or row of minimum size. For example, if you have 3 by 4 rectangle you unpainted rectangle will change like this: 3x4 -> 3x3 -> 3x2 (or 2x3, does not matter) -> 2x2 -> 2x1 (or 1x2) -> 1x1 -> 0x0 Every transition will give you one score point (except for last which gives 2 points because we paint one row and one column at the same time). You perform this sequence of operations on the first rectangle, keep track on the number of operations (cnt1) and score (s), calculate recursively min. number of operations for the rest of the rectangles to achieve (k — s) score (cnt2), choose min(cnt1 + cnt2) after painting sequence is complete.

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone explain, why the sample testcase 1 answer is 0. I think we can wait upto 19 minutes and then take the bus route 1 — 5 which will cost 30 minutes, and we will arrive on 5 at 49 minutes ?

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone help me find out the test case for which 276261336 problem C (test case 18), failed ?. Appreciate any help thank you :)

  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I found this test case:

    Test

    which in my code returns:

    Result

    and in yours:

    Result

    Hope it helps!

»
21 month(s) ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

For problem G sample 1, can someone share the route which corresponds to a starting time of 0? From what I understand of the problem, there should be no solution and the answer should be -1. Maybe I am overlooking something. I am copying the sample below for convenience.

5 5
100 20 80
1 5 30 100
1 2 20 50
2 3 20 50
3 4 20 50
4 5 20 50
  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    In time 0, walk through the edge from 1 to 5. That will take 100 units of time, which fits in t0.

»
21 month(s) ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

For Problem F, sample 6, reproduced below, can someone explain how the required 25 points can be obtained in 80 operations, as given in the sample solution?

3 25
9 2
4 3
8 10
  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    First we will completely fill the 2*9 and 4*3 rectangles. After this our score would be 18 and operations are 30. After this we will start filling the 8*10 rectangle in this order — 8, 8, 8, 7, 7, 6, 6. This would lead to a total score of 25 in 80 operations.

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

did any one solved F using greedy?

»
21 month(s) ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can anyone please explain what's wrong in my approach of problem G. I applied binary search to find how late we can start to reach on time. What I'm doing in my modified dijkstra is that if I can take bus then then will take it but if I will get a call in between or currently on a call then I will take the best of wait till the call is finish and take bus or walk.

My Code
»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone please explain me how are we getting 35 operations in last test case of sample? I am getting 36 operations to score 18 points.

4 18

5 4

8 5

8 3

6 2
  • »
    »
    21 month(s) ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Fill the 6 x 2 (score = 8 & operations = 12) rectangle and 5 x 4 rectangle (score = 9 & operations = 20) completely and one row of 8 x 3 rectangle (score = 1 & operations = 3). Therefore total operations and score would be 12 + 20 + 3 = 35 and 8 + 9 + 1 = 18 respectively.

»
21 month(s) ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Why am I not official in this round !!!

»
21 month(s) ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In problem G, why did I get TLE when I used priority_queue but after switching to set<pair<int,int>> it became AC?

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

is it possible to solve problem H using a segment tree

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

H can solve with segment tree, kadane and walking in the seg. if x is in the set, the value in the segment is -inf else 1

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Solve H with using a segment tree:

Let's use that $$$a_i$$$ $$$\leq$$$ $$$C$$$, where $$$C=2*10^6$$$

Let's imagine an array $$$nxt$$$: if the set currently contains a number $$$i$$$, then $$$nxt[i]$$$ is equal to the number of elements starting with $$$i+1$$$ that are not in the set. That is, if the next higher number than $$$i$$$ in the set is $$$j$$$, then $$$nxt[i] = j - i - 1$$$. If there is no next number, then we must set it to $$$inf$$$ (or a number that is definitely sufficient for the problem, namely $$$2*10^6$$$). If the number $$$i$$$ is not in the set, then $$$nxt[i] = 0$$$.

Let's construct a segment tree for maximum on the array $$$nxt$$$.

Query responses are then processed as follows:

1) $$$nxt[i]$$$ can be updated by changing the value at a point in the segment tree, using std::set to maintain the set's elements and quickly find the next higher/lower element

2) answering a query is equivalent to finding the first element from the left in $$$nxt$$$ that is >= $$$k$$$. This is a standard problem that can be solved either using binsearch + prefix max queries using a segment tree, which will yield a $$$O(log^2 C)$$$ per query, or by descending the segment tree, which will yield $$$O(log C)$$$.

Also note that you can't reset the segment tree for each testcase, as this will result to $$$O(C*t)$$$ appearing in the asymptotics and exceeding the time limit. You can do it this way: after processing all queries, iterate through the set of remaining numbers and reset the segment tree at these positions. Then all changes will take a total of $$$O((n + q) * log C)$$$

It's $$$O((n + q) * log C)$$$

(you can see my solution for a better understanding)