Intuition for  A. Doremy's Paint problem. 
Разница между en1 и en2, 28 символ(ов) изменены
Problem : :↵
==================↵


_________________________________________________↵
Doremy has n↵
 buckets of paint which is represented by an array a↵
 of length n↵
. Bucket i↵
 contains paint with color ai- ↵

Let c(l,r)↵
 be the number of distinct elements in the subarray [al,al+1,…,ar]↵
. Choose 2↵
 integers l↵
 and r↵
 such that l≤r↵
 and r−l−c(l,r)↵
 is maximized.↵

_________________________________________________↵
Understanding :↵
==================↵
This problem is basically ask for you have to give to pair which is to index (1 based) by which the algebraic function which is  r−l−c(l,r)↵
would be maximum, first of all there possible multiple solutions for a particular test cases but another condition is that l≤r (should hold true for any cases ). ↵
_________________________________________________↵
Approach:↵
==================↵
We can see basically an array need to be sorted first because we need maximum value of that function and if we sort it in ascending order then for each i we could possibly get an j for which value of a[i] and a[j] contracting to a positive increase like we know about a equation↵

f(l, r) = (r — l) — c(l, r)↵
 ↵
Where c(l,r) is the number of distinct elements in the subarray a[l...r].↵

So if we took intuition from that then we can see we only need to worry about inc function for which this function gonna increase. ↵

1. First you need to sort that array ↵
2. Then you have to Irritating though out the array as per principle indexing way ↵
3. Declare a set data structure which gonna handle for each unique value for principle test case calculation, which gonna use specifically contempt the size of Instant Array c(l,r) ↵
4.declear Boolean Function for the purpose of if you couldn't get the increase function after n-1th domain element counting (which always exist), then you just break the loops. ↵
5.declear one maxres which take care for your value of f(n) function , and declear left, and right which gonna take care of your indexing for that which max value of that function holds. ↵
6.your principle array is positive approaching and second domain array is negative approaching because we gonna check extreme most case first. ↵
7.then if after first declaration your maxres, left,right updates but for second that not holds which ovios then break . ↵
8.output left and right else its holds the you puts the 1  .  Size of the array. ↵


Thank you for your time. ↵

[submission:308467006]↵
My code. ↵

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en8 Английский Spaindiace 2025-03-01 14:07:39 98
en7 Английский Spaindiace 2025-03-01 11:37:44 216
en6 Английский Spaindiace 2025-03-01 11:36:28 71
en5 Английский Spaindiace 2025-03-01 11:35:36 65
en4 Английский Spaindiace 2025-03-01 11:34:50 67
en3 Английский Spaindiace 2025-03-01 11:32:39 53
en2 Английский Spaindiace 2025-03-01 11:31:24 28 Tiny change: 'Problem : \n________' -> 'Problem:\n==================\n\n\n________'
en1 Английский Spaindiace 2025-03-01 11:29:55 2506 Initial revision (published)