Блог пользователя bestial-42-centroids

Автор bestial-42-centroids, история, 10 месяцев назад, По-английски

Thank you for participating in our round ! We hope you enjoyed our problems. Feel free to discuss them in the comment section :)

/!\ The solution codes will be available in a few minutes

UPD: The solution codes have been added ! UPD2: The solution codes links are fixed ! Sorry for the inconvenience.

2128A - Recycling Center

Solution
Rate the problem

2128B - Deque Process

Hint1
Hint2
Solution
Rate the problem

2128C - Leftmost Below

Hint
Solution
Rate the problem

2128D - Sum of LDS

Hint1
Hint2
Solution
Rate the problem

2128E1 - Submedians (Easy Version)

Hint1
Hint2
Hint3
Hint4
Hint 5
Solution
Rate the problem

2128E2 - Submedians (Hard Version)

Hint1
Hint2
Hint3
Solution
Code
Rate the problem

2128F - Strict Triangle

We shorten $$$\text{dist}_w$$$ by $$$d$$$. We denote $$$d_L$$$ as the distance when every edge has weight $$$l_i$$$, and $$$d_R$$$ as the distance when every edge has weight $$$r_i$$$.

Hint1
Hint2
Hint3
Hint4
Hint5
Hint6
Solution
Rate the problem
Разбор задач Codeforces Round 1039 (Div. 2)
  • Проголосовать: нравится
  • +206
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

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

wow instant tutorial!

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

Thanks for the quick tutorial! Very good contest, I found problems level very well distributed. There wasn't a big gap in difficulty between consecutive problems, at least until E1. Well done!!!

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

C and E2 are cool, but neither D nor E1 should be in a div2

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

I got stuck at ABC, ironically. Nevertheless, D and E1 were fun!

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

You can now rate the problems in the editorial !

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

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

1486D - Max Median

problem E1 is similar to this

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

E1 was pretty easy comparing to div2 E. I have solved at least 3 problems which uses this similar idea

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

Whats the proof for submedian being monotonic for E1?

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

    did you get the proof

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

      This is my understanding, but it might not be correct. for a sub list and a V, you need to satisfy 2 conditions 1. big condition, the number of elements in the list greater or equal to V must bigger than (|list|+1)/2, which wishes V to be small 2. small condition

      submid want to fit the two conditions, which is not monotonic,for example [6,7,8] k=3, V=7 fit the two conditions, but V'=6 does not

      however for one condition, such as big condition is monotonic the smaller V is, the more likely the big condition to be fitted

      so we can binary search the biggest V to fit the big condition, and we also know the bigger V is, the more likely the small condition to be fitted

      let v be the largest V fits big condition, [ans_l:ans_r] be the sub list. [v, ans_l, ans_r] is the answer. how to prove it?

      we can infer v must be in the sub list if ith<v<i+1th, e[v]+g[v]-l[v]>=0, e[v]=0 (e stands for equal, g stands for greater, l stands for less, "ith" and "i+1th" respectively refer to the i-th and (i+1)-th largest numbers.) let v'=i+1th,l[v']=l[v],e[v']+g[v']=g[v], big[v']>=0 but v'>v The proof by contradiction holds.

      so e[v]>0, l[v+1]=l[v]+e[v] (v+1 stands for i+1th in sub list)
      big[v]=e[v]+g[v]-l[v]>=0
      big[v+1]=e[v+1]+g[v+1]-l[v+1]<0
      g[v+1]=g[v]-e[v+1]
      l[v+1]=l[v]+e[v]
      so big[v+1]=big[v]-e[v]
      because big[v+1] < 0
      so big[v]<e[v]
      so e[v]+g[v]-l[v]<e[v]
      so g[v]-l[v]<0
      so small[v]=e[v]+l[v]-g[v]>e[v]>0
      

      so the small condition is also fitted

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

    Instead you can just binary search on the condition that a median $$$\ge x$$$ exists iff in an array with $$$\text{b}[i] = 1$$$ if $$$\text{a}[i] \ge x$$$ else $$$-1$$$ you have some $$$\text{pref}[r] - \text{pref}[l] \ge 0$$$ with $$$r-l \ge k$$$ and there is nothing to prove. Also a classic trick.

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

      This is what I meant by the predicate being monotonic. Essentially: if you know there exists a submedian $$$\geq x$$$, then the largest submedian is $$$\geq x$$$.

      You might ask: what does it have to do with monotonicity ? Well, binary search on the answer can be explained like this:

      You define a function $$$f: \mathbb{N} \rightarrow {0,1}$$$ (note that $$$\mathbb{N}$$$ could be replaced with something else), Assume that function is increasing (so essentially, either $$$f$$$ is constant, either there exists $$$k$$$ such that $$$f(0) = f(1) = ... = f(k) = 0$$$ and $$$f(x) = 1$$$ for $$$x \gt k$$$. Binary search allows you to find that $$$k$$$ i.e finding the last $$$0$$$ (or equivalently, the first $$$1$$$).

      Now, in practice, it means that if $$$f$$$ is an "increasing", "question", you can find the smallest thing such that the answer to the question is YES.

      PS: of course, a similar thing holds for decreasing

      Sorry if it wasn't clear from the editorial

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

        Yes, I did understand that part. That line did indeed make it clear (editorial is great) that you could binary search on median $$$\ge x$$$. However, after that you talk about something else that is interesting (but I suppose isn't the easiest way to solve the problem) so I'm assuming that's what confused people. In my comment I just wanted to point out that you can ignore all that (although I know you probably included it to provide intuition) and just do the binary search with the sole fact that you have a monotonic predicate.

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

Interesting E2.

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

"and will increase $$$d(1,k) + d(k,n)$$$"

I think there's a typo here, we're decreasing the weight of the edge, that can't happen

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

Auto comment: topic has been updated by hugopm (previous revision, new revision, compare).

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

thanks for superfast editorial

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

D can be solved with dp too. Because of the constraint $$$ max(p_i, p_{i+1}) \gt p_{i+2} $$$, the $$$ LDS $$$ ending at index $$$ i+2 $$$ will always have one of $$$ p_i $$$ or $$$ p_{i+1} $$$ as the second last element. Hence, we get

$$$ dp_{i} = max(dp_{i-2} + (i - 2) + (i - (i - 2)), dp_{i-1} + (i - 1) + (i - (i - 1))) $$$
$$$ dp_{i} = max(dp_{i-2} + i, dp_{i-1} + i) $$$

This basically means that for jth index, all LDS ending at jth index will increase by 1 hence we get j increments and for all the elements after j, we will get a new LDS of length 1

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

WOW NICE TUTORIAL, I AM WAITING FOR RATING CHANEGS

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

The jump between E1 and E2 was huge. But great contest.

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

I had no clue about B till the very end but got C pretty quicklu. I dont know how so many people got it lol

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

Amazing E2. Walking from range of min to range of max is quite a cool trick, never thought I can use this trick from MO in CP :P

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

Can anybody explain the proof for C in simpler terms.

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

    for array -> [10,5,6,0,0,0,0.......]

    To be able to construct this array, it must satisfy the condition: Ai≤min⁡(A1,…,Ai−1)×2−1 for all 1<i<=n

    Why is that? Let me explain with the example of the third element (A2=6). The largest value we can achieve for A3 depends on the previous elements. We can add at most 5 in one turn, because adding more than that would affect A1. But we can do better than that by first adding 4, then adding 5 in subsequent turns, which ends up giving us 9 for A3. i think you can understand that now we can make it any elements in range 0 to 2mx-1

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

    Sorry this is a really informal explanation, I'm a newbie too.

    1. Try an arbitrary number like 40, the max you can build to the right of it is +39 then +40 =79. Try 5, the largest you can build is 4+5=9. For any n to the largest you can go is (n-1) + n. In other words next value < 2*n

    2. Its optimal to build left to right, you cant skip values (aka leave it at 0) if you want to build values to its right.

    3. You have to keep track of the minimum allowed as you go left to right. Say b[0] = 10 the limit is now 19. If b[1] =15 it's fine, because its within the limit. But the limit is still tied to 10*2 -1 =19, the lower value not 15*2 -1 = 29.

    If we were to try to build anything greater than 19 anywhere to the right of b[0], b[0] would have to increase beyond 10 first, as we have proved in point 1 the max it can go is 2*n -1.

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

very happy to see very less low ranked people in higher ranks.. do we have some new AI protection

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

Good contest, however I found C to be on easier side this time

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

is it possible to solve D without the max(pi,p_(i+1))>p_(i+2) condtion?

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

someone might've mentioned, but A is solvable in O(n).

for B, solvable by taking first two, then sorting left and right based on the previous 2 values

the answer for C is a bit confusing, but that might just be me. the solution i found simplest was to keep track of min value and ensure that all after it are strictly less than 2*(min value), which is probably exactly the same as the solution text, but a bit simpler worded for anyone that might be confused like me

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

    How is A solvable in O(n), i don't see it

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

      i solved it in nlogn dont know about o(n) tho

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

      simple, for each number a[1] to a[n] we go from 1 to 31 (k) and find the first power of two where (1 << k) * a[i] > c. we form a separate array where we keep track of how many numbers there are for each k. once we have this, we can simply go through the array and find out how many of the integers can be used for free. for this, a slight complication is the fact that if there are k's where p[k] = 0, which is why we keep track of how many zeroes there are, because they allow us to use more of the next values. in my code, this is accomplished via a variable called leeway. the total time complexity is O(t * n * 31), or O(n) for each test case, since the 31 is a constant. the code isn't bad so you might be able to clear up anything i've explained badly with it.

          #include <bits/stdc++.h>
          using namespace std;
           
          int main()
          {
          	ios::sync_with_stdio(false);
          	cin.tie(0);
          	cout.tie(0);
          	int t;
          	cin >> t;
          	for(int i = 0; i < t; i++) {
          		int n;
          		long long c;
          		int coins = 0;
          		cin >> n >> c;
          		vector<int> a(31, 0);
          		for(int j = 0; j < n; j++) {
          			long long x;
          			cin >> x;
          			if(x > c) {
          				coins++;
          				continue;
          			}
          			for(int k = 0; k < 31; k++) {
          				if(x * (1 << (k + 1)) > c) {
          					a[k]++;
          					break;
          				}
          			}
          		}
          		int leeway = 1;
          		for(auto i : a) {
          			coins += max(i - leeway, 0);
          			if(leeway >= i) {
          				leeway -= i - 1;
          			}
          			else {
          				leeway = 1;
          			}
          		}
          		cout << coins << '\n';
          	}
          }
      
  • »
    »
    10 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    WTH!!!! How is A solvable in O(n)???

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

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

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

I can't access the solution codes, pls fix this

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

A was diabolical in every terms. whoever created it needs to step down . I left the contest cuz of A thinking of an optimised way

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

Contest number 999999 to solve a problem using -1, +1 median trick and binary search on answer.

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

my solution for D is takes somewhat a different approach, i solved D with dp with a couple of key observations:

we first handle the lds problem individually for one singular array a[n], and define dp[i] as the longest lds ending with position i.

observation 1: in standard lds problems, dp[i] is usually computed from multiple previous states dp[j]'s where a[j] > a[i], j < i. however, due to D's unusual constraints, we can prove through contradiction that the only j's that are relevant is i-1 and i-2.

this observation decreases dp's computing time complexity to O(n).

observation 2: we can also prove (again by contradiction) that dp[i] >= dp[j] for all j < i. this brings to an important idea: since lds(1, i) equals to the maximum of dp values from 1 to i, lds(1, i) = dp[i].

now, define f(i) as lds(i, i) + lds(i, i + 1) + ... + lds(i, n). using the observations above, we can calculate f(1) in o(n) time. how can we transition f(i) to f(i + 1) quickly?

we can break it down into two cases:

if a[i] > a[i + 1], then a[i] is the maximum of the array a[i...n], which can lead to the fact that all lds(i, k), i <= k <= n starts with a[i]. so, all lds's are shortened by one, which gives: f(i + 1) = f(i) - (n - i + 1).

on the other hand, if a[i] < a[i + 1] then it can be proven that all lds(i, k), i < k <= n (notice the how its < not <=) does not start with a[i], since with k > i + 2 it it always better to choose a[i + 1] as the starting point rather to a[i]. so in this case, f(i + 1) = f(i) - 1.

now f(n) can be calculated in O(n), summing all f(i) gives the answer.

total time complexity: O(n).

code: link

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

The contest was fun! Enjoyed during the contest!

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

Auto comment: topic has been updated by bestial-42-centroids (previous revision, new revision, compare).

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

why my code failed for submission (problem a), what's wrong in my code ?

code: ~~~~~

include <bits/stdc++.h>

define ll long long

define all(v) v.begin(), v.end()

using namespace std;

bool check_bool(string str){ int i=0,j=str.size()-1 ; while(i<j){ if(str[i]!=str[j]){ return false ; } i++ ; j-- ; } return true ; } bool check_frq(string str){ map<char,int>mp ; for(int i=0;i<str.size();i++){ mp[str[i]]++ ; } bool ptr= true ; for(auto it=mp.begin();it!=mp.end();it++){ if(it->second%2==0){ continue ; } else { if(ptr==true){ { ptr=false ; continue ;}

}else{
        return false ;
       }
  }

} return true ; } long long gcd(long long a,long long b) { while(b) { long long t=a%b; a=b; b=t; } return a; } ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); } int main() { int t=1; cin>>t ;

while(t--){
  int n ;
  ll c;
  cin>>n>>c ;
  vector<ll>vi(n) ;
  for(int i=0;i<n;i++){
     cin>>vi[i] ;
  }
  sort(vi.begin(),vi.end()) ;
  int ans=0 ;
  int j=-1 ;
  for(int i=n-1;i>=0;i--){
     if(vi[i]<c)
     {
        j=i ;
        break ;
     }
  }
  int ptr=0 ;
  for(int i=j;i>=0;i--){
     ll x=ptr*vi[i]*(ll)2 ;
     if(x<c){
        ptr++ ;
        ans++ ;
     }
  }
  cout<<n-ans<<endl ;
 }
return 0;

} ~~~~~

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

Guys, how to notice facts like hint1 in D? Let bi=max(ai,ai+1), show that b1≥b2≥…≥bn−1.

I mean to say, how do I know what to look for?

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

    I have no idea. I feel like editorials do a bad job of capturing thought process. They focus more on proving a solution to be correct than showing people HOW to come up with a solution.

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

    Sorry, I don't really recall how I solved this problem but I can try an explanation.

    Perhaps a first remark you could do is that if the condition was that if a[i] >= a[i+1] for every i, then the array would be decreasing and LDS would be the whole sequence.

    So in a sense, max(a[i], a[i+1]) >= a[i+2] feels like that the array is "almost decreasing". Now to leverage that, you should get a feel of what "almost decreasing" means, in particular how much it prevents you from increasing. For that it can be helpful to try to generate arrays that respect the condition, and try to "feel the ceiling".

    Suppose you start with [50, 30, 40], now after the 40 you see that you must put something less than 40. Let's say you put 39, then after that you still must put something less than 40. You start to feel the ceiling. You wonder if you can increase back to something above 40, but you will quickly realize that's impossible, and that's what will make you realize that a[i] < a[i+1] implies a[i+1] > max(a[i+2], ..., a[n]), which is the hint2 (the hint1 is only useful to prove hint2).

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

Nice contest :D

Alternate solution for D:

Let dp[i] be the sum of all the subarrays that ends with the index i.

Set dp[0] = 1. Then, for 1 <= i < n, we have dp[i] = dp[i-1] + (i+1) if p[i] < p[i-1], and dp[i] = dp[i-1] + 1 otherwise. The answer is the sum of all the dp[i]s.

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

Why this solution isn't working for problem E1??

What's the reason?

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

    You cannot assume that the largest median can only be found in an interval of size k (like your solution calculates). In other words, it may be the case that the largest submedian can be found in an interval size >k.

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

      I calculate for interval of size k and k+1 (One even and odd length interval). I thought all other interval of size >= k+2 can be convert to these two cases.

      Edit: Now, I got it. One of case where my solution fails is:
      9 6
      1 6 6 1 3 3 4 8 8

      Expected Output: 6
      My Output: 4

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

Great contest, thanks :)

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

ai<x≤min(a1,…,ai−1)≤min(b1,…,bi−1).

Hence, bi=ai+x≤2x−1≤2mi−1.

Can any one help me with how final equation came from it previous step. That is how min(a1,...,ai-1)==2x-1?

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

F was literally useless in this contest. Nice contest overall !

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

These problems are such that you're just better off guessing something rather than trying to prove a solution. Don't make such problems please.

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

I really enjoyed E2 and it's a very cool problem. But I think making E1 worth 1750 (same as E2) was too much. It is really demotivating to see my score on E2 being less than my score on B.

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

Any idea about the rating of B & C?

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

I can solve E1 very fast because it was same as this problem

https://mirror.codeforces.com/problemset/problem/1486/D

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

Can someone please explain to me why my code for problem C isnt right?

The code in contest:

Code

The code after the contest (after i change a little bit to make it like the tutorial):

Code

But both are wrong, however.

Can someone please explain to me?

(I put both in void solve() btw)

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

Check my solution on D 331161296

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

I also have a dp solution for D.

Let $$$dp_i$$$ be the sum of LDSs of the segment $$$[i, j]$$$ with $$$i \leq j \lt n$$$ and $$$dp_i = 0$$$ with all $$$i \gt n$$$ and $$$LDS(i, j)$$$ be the LDS for the subarray $$$a_i, a_{i + 1}, ... a_j$$$

Due to the fact that $$$max(p_i, p_{i + 1}) \gt p_{i + 2}$$$, I claim (with no solid proof) that $$$LDS(i, j) = LDS(i + 2, j) + LDS(i, i + 2) - 1$$$ with $$$j \geq i + 2$$$

First, initialize $$$dp_n = 1$$$

Then consider $$$i \lt n$$$

We have 3 cases:

Consider the segment $$$[i, i]$$$. Clearly the LDS is 1. So first $$$dp_i = 1$$$

Then consider the segment $$$[i, i + 1]$$$. The LDS is 2 if $$$a_i \gt a_{i + 1}$$$ and 1 otherwise. So the contribution to $$$dp_i$$$ is either 2 or 1.

Next consider the remaining segments. According to the claim above, $$$LDS(i, j) = LDS(i + 2, j) + LDS(i, i + 2) - 1$$$ with $$$j \geq i + 2$$$. Since $$$LDS(i, i + 2)$$$ is a constant, and we have $$$n - i - 1$$$ subarrays starting from $$$i + 2$$$, we can deduce that the sum of the LDS in this case is $$$(n - i - 1)*[LDS(i, i + 2) - 1] + dp_{i + 2}$$$.

Therefore, my dp formula is as follows:

$$$dp_n = 1$$$

$$$dp_{n - 1} = 1 + LDS(i, i + 1)$$$

$$$dp_i = 1 + LDS(i, i + 1) + [LDS(i, i + 2) - 1]*(n - i - 1) + dp_{i + 2}$$$

Then sum all of the dp values to get the answer.

This runs in $$$O(n)$$$ time

Submission: 331179927

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

I do not understand how problems like E1 are allowed in Div2 style contests. E2 alone should have been enough.

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

not my dumb ahhh failed system test on A

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

submission link

Can someone please explain why my O(n^2) solution for C passes?

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

I don't think B is even a real problem‌.Actually,no matter how you write your program,it'll can be accepted.

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

I have a quite stupid solution for $$$C$$$

Iterate from $$$2$$$ to $$$n$$$, let the current number be $$$x_i$$$ and $$$mn$$$ be the minimum of all elements before it.

Also, let $$$l$$$ be $$$floor(\frac{x_i - 1}{2})$$$ and $$$r$$$ be $$$x_i - l$$$

Iff $$$max(l, r) \gt mn$$$ then the answer is definitely "NO" and otherwise.

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

After carefully studying your solution section, I feel that there might be a typo in the "It's optimal" part. If ai < a{i+1}, then a{i+1} must be greater than a{i+2}; otherwise, max(ai, a{i+1}) = a{i+1} cannot be greater than a{i+2}.

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

Can someone suggest some problem that involves considering all possible subarrays, like problem D?

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

I can't understand problem C at all.... can anyone help?

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

In prb D edi, shouldn't it be "if ai < ai+1 we cannot have ai+2 > ai+1" ?

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

I really appreciate problem E2, but I think this test should really have been considered. It's one of the easiest mistakes one can make while sweeping that they set answers for the whole $$$[min, max]$$$ range every time, instead of updating only the answers that are yet to be found.

The hack test $$$n=300\,000$$$, $$$k=2$$$, $$$[1,n-1,2,n-1,2,n-1,...,2,n-1,2,n]$$$ forces the minimum and maximum median to be at the very ends, and every range of even length (except for the very ends) to have $$$[2,n-1]$$$ as the median range. Thus, sweeping is performed for $$$\mathcal{O}(n)$$$ iterations and every second iteration it updates $$$\mathcal{O}(n)$$$ answers, leading to $$$\mathcal{O}(n^2)$$$ time in total.

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

D was an excellent problem and C was easy compare to other div-2 contest

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

E1 is such a good problem if it was provided in a div3 round, or an edu round.

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

i have a idea for problem D. We just need to notice that the sequence is a decreasing one. However, there may be some positions where it increases once. It is absolutely impossible for three numbers to be in increasing order. Therefore, it is easy to figure out the subsequent operations by drawing a diagram.

#include<iostream>
#include<vector>
#define int long long
using namespace std;
signed main()
{
    int t; cin >> t;
    for (int q = 0; q < t; q++)
    {
        int n; cin >> n; vector<int> v(n + 1, 0);
        for (int i = 1; i <= n; i++) cin >> v[i];
        int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            sum += (i * (n - i + 1));
        }
        int tar = 0;
        for (int i = 2; i <= n; i++)
        {
            if (v[i] > v[i - 1]) tar += ((i - 1) * (n - i + 1));
        }
        cout << sum - tar << endl;
    }
    return 0;
}
»
9 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i spent long on A~E1, i didn't solve E2 in the test. But that's really a good problem :)

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

What a tricky E1, but I like it.

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

There is a solution to problem D that does not need the statement max(p_i, p_{i+1}) > p_{i+2} to be true, and it does not have to a be permutation either meaning it will work for any array.

Ideas is to calculate for each index i where 0<=i<n, if r = i, what would the answer be and sum of them is the final answer. To calculate it we use idea of Longest Increasing Subsequence in O(n log n), but it is Longest Decreasing Subsequence now.

Overall time complexity is O(n log n).

Link to the submission: https://mirror.codeforces.com/contest/2128/submission/331402684

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

It appears that the dp approach for problem D is more intuitive to implement, when you try to figure out the relation with a paper.

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

A was very hard

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

This is my solution to problem D. First, consider the sum of the LDS of sub-segments starting with 1. Let f_i be the contribution of sub-segment [1,i].

Since $$$\max(p_i, p_{i+1}) \gt p_{i+2}$$$, transferring from $$$i$$$ and $$$i+1$$$ to $$$i+2$$$ must be non-degenerate.

Next, consider how to transfer from the sum of $$$\text{LDS}$$$ starting with $$$i-1$$$ to the sum of $$$\text{LDS}$$$ starting with $$$i$$$. Let $$$g_i$$$ be the sum of $$$\text{LDS}$$$ starting with $$$i$$$, and initialize $$$g_1=\sum \limits_{i=1}^n f_i$$$.

If $$$a_{i-1} \gt a_i$$$, then for all sub-segments, the transition from $$$i-1$$$ to $$$i$$$ is lost, so $$$g_i=g_{i-1}-(n-i+1)-1$$$. The final subtraction of 1 represents the contribution from the segment $$$[i-1,i-1]$$$, and the same applies below.

Otherwise, there is no loss, and $$$g_i = g_{i-1} + 1$$$.

The answer is $$$\sum \limits_{i=1}^n g_i$$$.

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

I am unable to view code. Kindly help me out

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

Dear Codeforces Team,

I am Ankit.Kushwaha, and I recently received a plagiarism warning for problem 2128C from Codeforces Round 1039 (Div. 2), associated with solution ID: 331146482. I respectfully wish to clarify that the submitted solution was written entirely by me, independently, during the contest using Visual Studio Code on my personal machine, without any external assistance or reference.

The approach I implemented involves maintaining the current minimum of the array while verifying that each subsequent element satisfies the condition arr[i] ≤ 2 * currentMin - 1, with a special check in case the minimum is zero. Given the simplicity and deterministic nature of the logic, it is highly likely that multiple participants may have arrived at similar implementations independently.

At no point did I upload or share my solution on any public platforms, nor did I utilize online IDEs such as Ideone or any other tools that could inadvertently expose my code.

I sincerely request a re-evaluation of my case. If any further information or clarification is required, I would be glad to provide it. Thank you for your time and consideration.

Sincerely,
Ankit.Kushwaha

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

E2 was nothing short of brilliant.

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

I personally find the editorial for D rather difficult to follow, and I want to suggest some changes.

There should be an assertion that $$$a_i = 0$$$ for all $$$i \gt n$$$.

The sequence $$$(i_1, ..., i_m)$$$ is not an LDS. $$$(a_{i_1}, ..., a_{i_m})$$$ is.

The optimality proof of the LDS is kind of hard to follow, and there's also a typo.

The statement "if $$$a_i \lt a_{i+1}$$$ we cannot have $$$a_{i+2} \lt a_{i+1}$$$" is wrong. It should be corrected to say: "if $$$a_i \lt a_{i+1}$$$ we must have $$$a_{i+2} \lt a_{i+1}$$$".

Here's my interpretation of the optimality proof. Please correct me if I'm mistaken or it can be improved.

Let $$$I$$$ be the index sequence $$$(i_1, ..., i_m)$$$ from earlier, and $$$E$$$ be the index sequence of any LDS of $$$a$$$. Let $$$i$$$ be an arbitrary integer in $$$[1, n]$$$, and consider the following.

  • If $$$a_i \gt a_{i+1}$$$, then $$$i \in I$$$ by definition. For $$$E$$$, $$$i$$$ may or may not exist.
  • If $$$a_i \lt a_{i+1}$$$, then $$$i \notin I$$$, but $$$i+1 \in I$$$ (because of the condition $$$\max(a_i, a_{i+1}) \gt a_{i+2})$$$. For $$$E$$$, at most one element in $$$(i, i+1)$$$ can exist.

In both cases, $$$I$$$ always takes at least the number of elements from $$$E$$$, so $$$|I| \geq |E|$$$.

I know these are subtle changes, but I think they can help clarify some points of the editorial.

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

I think the editorial for F is incomplete (and I arrived at the solution with this exact incomplete reasoning lol). You don't really show that the condition $$$d_L(u, v) \lt d_R(u, k) + d_R(k, v)$$$ holding for all $$$u, v \in P$$$ suffices for any path $$$P$$$ (you show this for some shortest path $$$P$$$, and make use of properties of shortest paths), which is required as our Djikstra's-like algorithm later isn't really being forced to only consider shortest paths.

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

    The necessary part incorrectly assumed that $$$P$$$ was shortest in $$$w_P$$$, my bad. But we can make things work as follows.

    TLDR: instead of looking at $$$d_L(u, v)$$$, look at the length of the subpath of $$$P$$$ going from $$$u$$$ to $$$v$$$.

    Let $$$P$$$ a path from $$$1$$$ to $$$n$$$. For every $$$u \in P$$$, let $$$\delta_u$$$ the sum of $$$l$$$-weights of the edges of $$$P$$$ that leads from $$$1$$$ to $$$u$$$. In particular $$$\delta_1 = 0$$$ and $$$\delta_n$$$ is the length of $$$P$$$. As you pointed out, $$$\delta_u$$$ might be larger than $$$d_L(1, u)$$$.

    Let's say that $$$P$$$ avoids $$$k$$$ if $$$|\delta_u - \delta_v| \lt d_R(u, k) + d_R(k, v)$$$ for all $$$u, v \in P$$$. This is different from what I said in hint 2.

    Let $$$w_P(e) = l(e)$$$ if $$$e \in P$$$ and $$$r(e)$$$ otherwise, and $$$G_P$$$ the corresponding weighted graph.

    Claim 1: if there is a valid assignment $$$w$$$ of weights, then there exists a path $$$P$$$ that avoids $$$k$$$.

    Proof

    Claim 2: if a path $$$P$$$ avoids $$$k$$$, then $$$w_P$$$ is valid (even if $$$P$$$ is not a shortest path in $$$G_P$$$).

    Proof

    Dijkstra algorithm either

    • finds a path $$$P$$$ that avoids $$$k$$$ (that may or may not be shortest in $$$G_P$$$), in which case by claim 2, the answer is YES.
    • tells us there is no path $$$P$$$ that avoids $$$k$$$, in which case by claim 1, the answer is NO.
»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In d solution you mean "if ai<ai+1 we cannot have ai+1<ai+2" Instead of "if ai<ai+1 we cannot have ai+2<ai+1" right?