SpyrosAliv's blog

By SpyrosAliv, 13 months ago, In English
Comment

Problem A — Souvlaki VS. Kalamaki

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem B — Siga ta Kymata

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem C — Monopati

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem D1 — Diadrash (Easy Version)

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem D2 — Diadrash (Hard Version)

Special thanks to Friedrich for figuring out the better solution.

Solution
Implementation
Rate the Problem
Rate the Difficulty

Problem E — Plegma

Solution
Implementation
Rate the Problem
Rate the Difficulty
  • Vote: I like it
  • +166
  • Vote: I do not like it

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

first.

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

B is too hard for div2

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

Bad contest

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

B is the worst problem

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

I hate the trend of C being easier than B..

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

If only I have seen C before B :(. I spent a lot of time on B, and still couldn't solved

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

Mistaken order of B and C will eat my huge rating:(

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

Ok, over all Bs difficulty mostly comes from the strange statement. At first, I was sure that $$$\max (p_l, p_r)$$$ referred to the whole range. But once you realize that it is not the case, then the following observations really help:

  • Can the leftmost element be 1? No
  • Can the rightmost element be 1? No
  • Can the minimum element be 1? No
  • Can the maximum element be 1? No

And then you ask yourself, since I have those elements that can never be one, can I use them to create ranges that are able to create everything else? And the answer is yes!

  • »
    »
    13 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +6 Vote: I do not like it

    That feel like pure guessing. I got the four observations you listed almost immediately, still couldn't solve it but coming up with false greedy solutions.

    How to be good at this kind of problems?

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

      Uhhh, I think that's kinda the point of codeforces... There are a lot of problems that require knowing how and where to guess.

      I personally find that there are a lot of easy problems that are sometimes surprisingly tricky. I remember like a year ago I found a 1200 rated problem that just killed me: I had NO idea how to solve it in any reasonable way.

      So I think that overall to get better at them... well... just do more problems xd

      Although perhaps it could make sense to actually sort problems in the range 1000 to 1800 by least solved, and perhaps then you can find problems that are surprisingly annoying/weird/etc

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

        Maybe I really should do more CF problems :P

        Although perhaps it could make sense to actually sort problems in the range 1000 to 1800 by least solved, and perhaps then you can find problems that are surprisingly annoying/weird/etc

        I never thought of that, will try it someday. Thanks!

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

      It's not really guessing of you instead consider a certain element and try to make it one, you will notice immediately it's impossible when it's a min or max, then that it can't be on the edges of the array. The argument for why it's impossible to turn these into ones naturally leads you to why it's possible to do that for the others. Finally you notice that there are 5 interesting ranges ( combining edges of the array and min/max ) that turn everything else into one.

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

    Could you please explain your initial approach in simpler words, it is somewhat difficult to understand for a newbie. Would mean a lot

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

      So for me, it was kinda like pattern recognition... I made those four observations and asked myself if, since they can never be painted, maybe they're the only ones that can never be painted and that I can paint all the others in at most 5 operations.

      And so I actually took out my notebook and started drew out the borders, after which I connected them all and got 5 meaningful ranges.

      I'm afraid I can't go much more in-dept than that... I recommend that you focus on lower rated problems for now so as to be able to more easily attempt these kinds of problems >:)

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

after seeing the soln b seems awesome; if only i had figured that out in contest ; hopefully i would be able to solve similar problems in future contest

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

ok, thanks for quick editorial.

I got cooked by B

»
13 months ago, hide # |
← Rev. 3  
Vote: I like it +7 Vote: I do not like it

Problem B:

What is the meaning of hold at the same time ?

My Interpretation : If any only if for all i , sunch that l<i<r , min(pl,pr)<pi<max(pl,pr) ?

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

Can anyone tell me what's wrong with my solution for C? 348365560

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

E: Let $$$r,c$$$ the input for the second run (both are binary strings with length of $$$n$$$).

  • If $$$r \le c$$$, $$$C=1$$$
  • If $$$r \gt c$$$, $$$C=0$$$

We can construct such input at the first run.

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

    This is indeed a correct alternative solution for problem E

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

    Whats the proof that you can always construct such input at the first run?

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

      Suppose every column and row satisfy $$$r \gt c$$$ and $$$C=1$$$,

      Choose any $$$c$$$ which has at least one 1, consider row $$$1$$$. It should have at least one 1. Then, we got a column with first element is 1. As a result, the first column will be full of 1. No row can be greater than this column.


      Suppose every column and row satisfy $$$r\leq c$$$ and $$$C=0$$$,

      Choose any $$$r$$$ which has at least one 1, consider column $$$1$$$. It should have at least one 1. Then, we got a row with first element is 1. As a result, the first row will be full of 1, and every column is full of 1, and the connectivity is $$$1$$$ now.

      • »
        »
        »
        »
        13 months ago, hide # ^ |
         
        Vote: I like it -6 Vote: I do not like it

        it seems like a proof by contrast. but I still don't get it. can you please elaborate on how the connectivity is related to the row and column dictionary order please?

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

          As mentioned above, there're no binary grid that satisfy every $$$r \gt c$$$. And the only $$$2$$$ binary grid that satisfy every $$$r\leq c$$$ is full-0 and full-1, which is either illegal or has $$$1$$$ connectivity.

          So actually row and column dictionary order and the connectivity have almost no connection. The only thing we need to ensure is the corner case of full-1 binary grid.

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

            thanks, that makes sense.

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

    But what if $$$C=1$$$ and all rows are lexographically greater than all columns (and also $$$C=0$$$ in contrast)?

    Is there a proof that such case cannot exist?

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

      When 1st row and 1st column have both $$$0,1$$$, it's ok.
      When 1st row and 1st column have only one character, we can cut down them.
      Only treating 1st row has no $$$1$$$ is ok (other case can be treated in the same way).
      1st row is $$$00\dots0$$$ and we have some $$$1$$$ in 1st column, so $$$r \lt c$$$ can be constructed.
      some row is $$$1?\dots?$$$ and all column is $$$0?\dots?$$$, so $$$r \gt c$$$ can be constructed.
      Edge case is a grid which have only $$$1$$$, but it's ok because then always $$$r=c$$$.

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

        I wonder the sufficiency of such a construction: e.g. I can make 2 examples demonstrating the same logic:

        101 010 101 which has both 0 and 1 in the 1st row and col and it's not connected.

        110 110 000 which has both 0 and 1 in the 1st row and col and it's connected.

        how is that connectivity decides whether there's such a configuration?

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

          Connectivity is not matter. We can always find $$$r \lt c$$$ or $$$r \gt c$$$ unless the grid has all the same character.

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

            Oh, I see your point. regardless of whether the graph is connected or not. we will have guaranteed that we can choose a row >= a col or a row < a col.

            we just choose such a pair of row and col to deliver such a message denoting whether the graph is connected or not.

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

I think I came up with the correct D2, but forgot to submit it imao. Might be one of my worst blunders ever.

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

for every i such that l<i<r and min(pl,pr)<pi<max(pl,pr) hold at the same time, you will set si to 1

Isnt this line so confusing, "for every i" part. the condition doesnt seem to hold true for every l<i<r (min(pl,pr)<pi<max(pl,pr)) in the arr. take this

5 3 4 2 1 5 01100

here non pass 5 1 5 1 4 5 5 4 5 4 5

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

the round except problem B is good

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

For B for me a big hint was that you needed to figure out if it was possible in less than 5 moves. If that 5 could be any number then you could binary search the answer and would get the minimum number of moves, yet the problem specifically said that you do not need to find the minimum number of moves so there was something special about the number 5...

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

    5 is special because you can always do it in at most 5 moves, given that its possible ofcourse, and the figure 5 comes from that fact that u need at most 5 ranges to so.

    For a string s where it is possible to do so,

    the ends and the min/max permutation element would have their corresponding bit

    in the string to be 'O'

    so s if of the form 0 1 0 1 0 1 1 0 0 (min_index) 1 1 0 0 1 1 0 0 (max_index) 1 1 0 0

    then we can always just pick the ranges

    1 to min

    1 to max

    min to max

    min to n

    max to n

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

I used another approach for C. So the idea came from that, for any path from (1, 1) to (2, n), we first go right, then down, then right again. So we can iterate each position i where we go down. And for fixed i, get the minimum value and maximum value on the path (1, 1) -> (1, i) -> (2, i) -> (2, n). This can be achieved by maintaining prefix min/max for the first row and suffix min/max for the second row.

Suppose for one path, the minimum value is L, maximun value is R. Then R, R + 1, ..., 2n is all legal for L. Also, R, R + 1, ... 2n is all legal for L — 1. So we can maintain the smallest R for every L when calculating each path. And after calculating L and R for every path, we can iterate L from 2n to 1, while maintaining the smallest R, and for every L, accumulate 2n — R + 1 to get the final answer. Here is my submission.348331154

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

    I came up with the same idea.

    But to get to the final count, After calculating L and R for each path,

    I took the max L amongst all paths and minR amongst all paths and then the final count would be

    maxL * (2 * n — minR + 1)

    But idk why it fails?

    348847633

    UPD: Figured out what was wrong, taking maxL is wrong because, its possible that when we obtained a particular L value, it came from a path where the R value was > minR which means i would end up counting extra pairs for this particular L

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

      Yes you are right. if you get the MinR from some (L, R) with a small L, then maybe you can't use this MinR for larger L.

      Take this case for example.

      5

      3 3 3 2 2

      10 10 10 3 9

      Using your code, you would get MaxL = 3, MinR = 9. However you get MinR = 9 only when L = 2. So you can't use (3, 9).

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

    C.Monopati

    Can you help me to find where my approach failed?

    https://codeforces.me/contest/2163/submission/359292937

    I track the min and max of each path and use the delta to calculate the change in each path to find the legal l&r.

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

Eventually reach Candidate Master after reaching Expert for over 500 days. Really really happy. Thanks for the great contest! ヾ(^∀^)ノ

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

I think, the purpose of some Div2B problems is not to be solved.

»
13 months ago, hide # |
← Rev. 5  
Vote: I like it +40 Vote: I do not like it

i have a fun solution for E that is i think simpler than the one in the editorial: 348371787. though i was not yet able to prove its correctness. i have to prove that if all rows and all columns contain the same number of ones, then either the grid is disconnected or there are no zeros at all.

upd: the solution is wrong. i apologize. here is a counterexample:

1 1 1 0

1 0 1 1

1 1 0 1

0 1 1 1

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

    The good one that passes the tests, but fails on hacks :D

  • »
    »
    13 months ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it +8 Vote: I do not like it

    Before reading this I came up with something similar and I think an extension of this idea works.

    Spoiler

    Concise implementation here: 348401861

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

    sob bro

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

guessed the solution for B in the last minute and it was correct

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

whenever you get stuck on an easy question that requires an interesting point, come up with 10-20 different examples and try to solve it. you will automatically come up with the answer!!

Meanwhile, B,C were great! "C" 's implementation was beautiful :)

UDP: Now i realize i provided a different solution for C :) and it's in O(n)

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

adhocforces

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

After seeing problem B felt like codechef, where questions are tangled around greedy ideas. I don't hate or like problem B but felt like thinking>>>coding.

»
13 months ago, hide # |
← Rev. 2  
Vote: I like it +3 Vote: I do not like it

https://codeforces.me/contest/2163/submission/348377026 Problem C can someone explain why this fails ??

I tried merging the global left and right accordingly (does the order of the max and min, of the down right path affect this ?)

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

in problem B, min(p_l,p_r) is minimum over the range (l, r) or minimum of p_l and p_r ??

»
13 months ago, hide # |
← Rev. 4  
Vote: I like it +3 Vote: I do not like it

D1 also has a Nested binary search on answer solution which makes the number of queries = 2*log^2(n) 348380335

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

can some one explain why cant we use merge intervals approach to merge them ?

    vector<vector<int>>v;
    for(int i=0;i<q;i++){
        cin>>x>>y;
        v.push_back({x,y});
    }
    sort(all(v));
 
    vector<pair<int,int>> inv;
    int start = v[0][0] , end = v[0][1];
    for(int i=1;i<q;i++){
        if(v[i][0]>end){
            inv.push_back({start,end});
            start = v[i][0] , end = v[i][1];
        }else{
            end = max(end,v[i][1]);
        }
    }
    inv.push_back({start,end});

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

    you are not merging them .

    you are removing the ranges that are $$$\textbf{inside}$$$ another bigger range

    so two ranges (1 , 5) and (4, 6) should both be added but if the second one was (2, 4) we can remove it .

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

B -> another approach : we can replace cout << min(mn, mx) << " " << max(mn, mx)** with cout << 1 << " " << n**

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

    No, we cant replace it. Think about the permutation 1 3 4 5 2 , if you replace min(mn,mx) and max(mn,mx) with 1 and n, that means we cant set any si to 1, cause max(p1,p5) is 2 and min(p1,p5)is 1.

    • »
      »
      »
      13 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
      cout << 1 << " " << mn << "\n";
      cout << 1 << " " << mx << "\n";
      cout << mn << " " << n << "\n";
      cout << mx << " " << n << "\n"; 
      cout << 1 << " " << n<<"\n";

      this will be there so soln exist if 3,4 will have to be set to 1 and if u will try to get one at 1,5,2 then by any method u cant get soln

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

My friend kafamcokkaristi wrote 348316517 a divide and conquer dp optimization for problem C, but we managed to create a case where it seems to take $$$O(N)$$$ distinct values, leading us to believe it runs in $$$O(N^2 \log N)$$$ in the worst case. However, from the assert() statements we added, we observed that this value is actually $$$≤ 5$$$ in the tests. Still, since hacks are disabled in recent contests, we can’t submit a hack; could you please add it manually? SpyrosAliv Proof_by_QED

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

Interesting insight of problem D2. my D1 solution is based on binary search as well but D2 takes it to a new level. Loved the idea of Mex[l, r] = min(Mex[1, r], Mex[l, n])

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

Is it possible to minimize the number of operations in B?

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

Nice solution for E1 : Assume We want to check either m can be MEX or not what should I do ?

-> first we find the smallest right index where MEX(a[1]...a[right]) >=m . Similarly find the largest left index where MEX(a[left] .. a[right]) >=m . Now check either this range belongs to any given range or not. And yes this is the answer . Use nested binary search .

Total query 2*log(n)*log(n) Solution Link : https://codeforces.me/contest/2163/submission/348367619

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

Feels like the D2 idea is kinda being overlooked... The fact that the MEX of a segment equals the min of the MEX of two other segments seems useful (hopefully)

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

    Yeah, it feels crazy to have never heard/thought of that. Very nice problem.

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

its alright if b was harder then expected. i really enjoyed the problem although i was not able to solve it.

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

Sorry if it's obvious, but for D1, how do we guarantee the number of queries is at most $$$300$$$? This is the single issue I haven't resolved with the same solution during the contest.

EDIT: My bad I misread the problem... See below. Thanks fugazi_zeitgeist.

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

Problem B:

why taking the whole range wont give the answer? cause if s is 1 for min and max the answer would be no and for every other number the answer would be possible. ~~~~~ // this is code

string s;

cin>>s;
f(i,0,n){
    if(s[i]=='1'){
        if(v[i]==1 || v[i]==n || i==0 || i==n-1){
            cout<<-1<<endl;
            return;
        }
    }
}
cout<<1<<endl;
cout<<1<<" "<<n<<endl;

~~~~~

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

    you misunderstood the satement as me. we cant take the whole range cause max(pl,pr) and min(pl,pr) doesnt hold for the whole range of [l,r] but only for the two numbers pl and pr.

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

B's Description was misleading for me.Was solving some different problem for sometime.

Then, for every i such that l < i < r and min(p_l, p_r) < p_i < max(p_l, p_r) hold at the same time, you will set s_i to 1.

hold at the same time? Didn't tell what holds at the same time.

One direct way to interpret this is -> if this conditions holds for all i at the same time then set s[i] to 1.

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

I solved (actually not) problem B and minimized the operations. Let i, j be the indices of the first and last units in x, then we can find mn1, mx1, mn2, mx2 in the range from 0 to i — 1 and from j + 1 to n — 1. Let's take the indices (mn1, mx2) and (mn2, mx1). After these operations, if s != x (if x[k] = 0, then we will not touch s[k]), then we output -1, otherwise these two operations. Unfortunately, I can't look at the tests, this solution gave WA 2 system test on test case 455. I really wonder why it doesn't work.

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

    It doesnt work for the situation: 7 1 4 6 7 3 5 2 0010100

    then you will use two intervals [1,6] and [2,7] but these two intervals cant let s3 became 1, cause your greatest chosen number if 5 , it is not greater than 6.

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

I was confused by the statement of B. I thought min(pl,pr) and max(pl,pr) holds for every pi which l<=i<=r ,and we just have to cout<<1<<" "<<n<<endl and all number except p1,p1,pmn,pmx could be counted.

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

Well.First, I need to thank the creator of this contest, because I have gained 172 ratings in this Div2.
But, I also need to say: What the f*** is Problem B?????

I think this sentence is bad: " $$$\min(p_l,p_r) \lt p_i \lt \max(p_l,p_r)$$$ "

It gave me -6 in B.

And I found it after CONTEST ENDING!!!!!

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

Could anyone tell me why my approach is wrong in question C https://codeforces.me/contest/2163/submission/348420021

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

    It recounts a set of indices. For example, it's possible that for one index, valid set of indices are (1, 3), (1, 4), (1, 5) and then for next index, another valid set of indices are (1, 3), (1, 4), (2, 3), (2, 4). According to your code, it will take the maximum of the minimum as the left index (2 in this case) and minimum of the maximum as the right index (3 in this case) and then form all the combinations which also includes (2, 5) which is not there originally. I also made this mistake many times in this question

    • »
      »
      »
      8 months ago, hide # ^ |
      ← Rev. 4  
      Vote: I like it 0 Vote: I do not like it

      How is it possible that $$$(2, 3)$$$ is a valid combination but $$$(2, 5)$$$ is not?

      If $$$(a, b)$$$ is valid then $$$(a - i, b + j)$$$ is valid for any $$$i, j$$$ such that $$$(a - i \ge 1) \land (b + j \le 2 * n)$$$. Isn't it true?

      In other words, we have $$$a$$$ ways to choose the first index and $$$2 * n - b + 1$$$ ways to choose the second index. But solutions using this idea do not work for some reason.

      UPD: I think I have found a counterexample:

      $$$ \begin{bmatrix} 3 & 1 & 6 \newline 5 & 4 & 2 \end{bmatrix} $$$

      If anyone's wondering why their solution fails, it might be insightful to test it against this test case.

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

Please help! What's wrong in my solution for D1? solution

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

It would be great if you could add hints and then solution.

»
13 months ago, hide # |
← Rev. 2  
Vote: I like it +4 Vote: I do not like it

funny thing is I thought I could do atmost 300 queries lol in $$$D1$$$ ,my solution does 210 queries at max there could be a medium version of this problem I think

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

is there a more rigorous proof for After cleaning out those ranges, we are left with at most n ranges ??

I get the intuition that it's true but I couldn't make sure that that's actually the case.

My thinking is that

  1. If we assume that there's no overlapping segment, then $$$|q|$$$ would be at most $$$n$$$ by having $$$[1,1],[2,2],[3,3],...,[n,n]$$$

  2. If we assume that there's overlapping segment, then $$$|q|$$$ would be at most $$$n-1$$$ by having $$$[1,2],[2,3],...,[n-1,n]$$$.

But I still couldn't ensure my mind enough that clearing those segment will result in no-nesting $$$q$$$ with having $$$|q| \lt = n$$$

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

For problem B:

First,we begin by mapping each element $$$p_i$$$ to a point $$$(i,p_i)$$$ on the plane. The given operation is then equivalent to setting the value $$$s_i$$$ to 1 for every point $$$(i,p_i)$$$ that lies within a specified rectangle.

Second,though painting we can know there is only four useful points: $$$(1,p_1),(n,p_n),(mn,p_{mn}),(mx,p_{mx})$$$.Then you will find the solution immediately.

349532383

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

O(n) solution for C ->353668810

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

D is amazing!

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

good for D

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

Can anybody explain the check function in problem C solution? Like is the straight line through first row or the second row not count? That is what it seems like to me..

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

D was amazing

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

Problem C can also be solved with binary search as you can loop through each number from 1 to 2N (letting the left bound be the current number) and greedily finding the lowest endpoint you can match it with since you know that every endpoint greater than that is sufficient as well.

Submission: 361215529

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

idk why people think 2 question is hard it is too easy man :) why the hell in world it is rated 1700

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //code-- void solve() { int n;cin>>n; vvi v(2,vi(n)); FOR(i,0,2){ cin>>v[i]; } int l=v[0][0]; int r=v[0][0]; int y=0; FOR(i,0,n-1){ int x1,x2; if(y==0){x1=max(v[y][i+1],v[y+1][i]); x2=min(v[y][i+1],v[y+1][i]);} else{ x2=x1=v[y][i+1]; }
l=min(l,x1); r=max(r,x2); if(y==0 && v[0][i+1]> v[1][i] && l<v[1][]){ y=1; }

}
l=min(l,v[1][n-1]);
r=max(r,v[1][n-1]);
debug(l,r);
cout<<l*((2*n)-r +1)<<endl;

}