### dreamoon_love_AA's blog

By dreamoon_love_AA, history, 2 months ago, , author's code:
author's code
author's code

UPD: onthefloor provides proof for what I mention here.

author's code
author's code (from bottom to top with min heap)
isaf27's code(from bottom to top with sorted array)
author's code (from top to bottom)
author's code
isaf27's solution
author's solution   Comments (187)
 » 2 months ago, # | ← Rev. 2 →   Check out the video editorialsAlso, you should add the codes under spoiler dreamoon_love_AA
•  » » Thanks to you very much!
 » Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).
 » I had different approach for Div2B, which is probably more intuitive.Lets calculate two values: $rpref[i]$ — the number of different elemtens in ith prefix.$rsuf[i]$ — the number of different elements in ith suffix.So lets fix l1. Our task is to check that sequences from [1 to l1] and from [l1 + 1 to n] are permutations. How to check this?Sequence from [1 to K] is permutation if and only if sum(1..k) = k * (k + 1) / 2 and rpref[k] = k. We can do same procedure for suffixes.My submission: https://codeforces.com/contest/1330/submission/75366634.
•  » » I thought the same maybe I missed something X0 here
•  » » » same here i got tle using same approch can someone check where my problem is -- help would be much appriciated https://codeforces.com/contest/1330/submission/75452454
•  » » » » 4 1 1 2 6 1 maybe you can try this example. the answer is 0 but sometimes the answer is 4 1 if you ues presum
•  » » » » __SON-GOKU__, I rewrited your code and it got AC.You had a few problems.1) MAX should be at least 2e5.2) Look at these lines: Spoilervector distinct1(MAX,0),distinct2(MAX,0);To create vector<||> distinct(MAX) is spent $O(MAX)$ time which means that on each test-case you were doing $O(MAX)$ iterations which naturally causes TL.3) #define int long long
•  » » » » » thanks man
•  » » » 2 months ago, # ^ | ← Rev. 3 →   luG_0, I found mistake in your code. In second check you should rewrite check(i+1, n,a) -> check(i, n,a), because your function checks from [a;b). I submitted your code and it got AC.P.S. Sorry for my poor english
•  » » » » thanks demon.machine how silly of me!!
•  » » » » hey my logic was same as yours but i was unable to find how to correct it :( https://codeforces.com/contest/1330/submission/75427713 please correct my code . thanks in advance
•  » » » » » Just write #define int long long.
•  » » » » » » thanks a lot :)
•  » » How is it more intuitive?
•  » » hey my logic was same as yours but i was unable to find how to correct it :( https://codeforces.com/contest/1330/submission/75427713 please correct my code . thanks in advance
•  » » » Hey u have declared pre and suf array as integer but the sum might exceed max value of integer.Declare it as long long
•  » » I used the same approach but solution is failing on test 3 can you please look at the solution https://codeforces.com/contest/1330/submission/75404652
•  » » » You have the same mistake as many other participants — Overflow. $sum[i+1]=((i+1)*(i+2))/2;$, but $i$ is Integer in your code. I replaced int i with ll i (or you can add (ll) before your formula). To avoid this sad mistakes i write #define int long long.
•  » » » » 2 months ago, # ^ | ← Rev. 7 →   https://codeforces.com/contest/1330/submission/75501441 gives wrong answer on test 2. everything is working properly except for input number 74 output is repeated 2 times. please help to correct it.
•  » » » » » Check this test-case: Spoiler151 3 2 2 1Answer is 3 2.
•  » » » » » » its coming 3 2 but printing two times. i don't know why.?
•  » » » » » » » try to debug by yourself
•  » » » » » » » Oh. I got it. I didn't check for same values hence when it checks from left to right and right to left it gets the same partitions but counts them as two
•  » » » » » » » » https://codeforces.com/contest/1330/submission/75511394still test 2 failing. please help. don't have a clue for what is wrong
•  » » My idea is similar to the one you use:I do not calculate to:rpref[i] — the number of different elements in i-th prefix. rsuf[i] — the number of different elements in i-th suffix.Because it is also not difficult to see that for a solution to exist no number can be repeated more than twice, so what I do is check that this is true, and then I say that: Sequence from [1 to k] is permutation if and only if sum(1..k) = k * (k + 1) / 2 and max element in the sequence (1...k) = k. We can do same procedure for suffixes. My submission with Prefix Sums: 75496699 My submission with Wavelet Tree: 75442213
•  » » How to count different elements in fast way? I thought the same but time limit
•  » » » There is a standard way to do this: Keep a variable called numDistinct; Also use an array or map count[] where you increment count[x] whenever you see x. Then after some increment of count[y], check whether count[y]=1. If so, then this is the first time seeing it, so increment numDistinct.The same thing can be done when removing elements. Then you would decrement count[y], and afterward check if it became 0; if so, then decrement numDistinct.
•  » » » nlogn way to do this is to input everything in a set and check set size, it's O(n) if you're using a hashmap(java and python), otherwise use the method detailed in the other comment
•  » » Hi, I had thought of the same approach, but my code is failing on TC8, My submission
•  » » I had a similar ideia (prefix and suffix arrays), but in $O(nlogn)$ using a set, it's pretty easy to understand:Let's say you have $n$ elements in a set and smallest element is $1$ and biggest element is $n$, then it's easy to see that the elements in this set is the same of a permutation of size $n$, since there are $n-2$ elements between $1$ and $n$ and they can't repeat so Pigeonhole principle -> exactly each element from $2$ to $n-2$.Now how does that help?Iterate through prefixes and insert $i$-th element into set. If the size of the set is equal to the length of the $i-th$ prefix, first element is $1$ and last element is $i+1$ (0-based index), then you have a permutation so you can set $prefix[i] = true$Do the same for suffixes.Now you can split sequence into two permutations at the $i$-th position if and only if $pref[i] == true$ and $suf[i+1] == true$.
•  » » 5 weeks ago, # ^ | ← Rev. 2 →   Heyyy, hope you are doing well...I went through your approach in 1330B-Dreamoon Likes permutations. https://codeforces.com/contest/1330/problem/BActually I was trying out a similar approach like.... if I get the prefix sum = i(i+1)/2 and the other part( total sum — prefix )also matches one such sum, I am just checking whether any no.is repeated or not as 4+3+2+1 = 4+3+3. I am checking by the logic that suppose the no.s are 4,2,3,1 then the count of them should be max of them, i.e 4. In case of 4,3,3 the count will be 3. Here is my solution... https://codeforces.com/contest/1330/submission/77888159 Can you just help me out ? @dreamoon_love_AA I'm getting wrong in the 1454th case of sample 2. Can you kindly help ?
 » Nice contest, D1B is beautiful!
•  » » Thank you~
 »
•  » » I've been trying to make sense of this problem for long. Thanks!
•  » » thanks div2C explanation is really helpful.
 » Amazing contest.
•  » » Thank you~
 » 2 months ago, # | ← Rev. 2 →   Somebody explain Div2D in smaller steps?I understand that we need to choose a[i] in a way that we add at least one bit to b[i-1], and we can remove all lower bits. How does this lead to closed formular for fixed a, or sum of "some" a[]s?
•  » » 2 months ago, # ^ | ← Rev. 2 →   Suppose x is some element of our sequence (say at index u). Suppose the i-th bit of x is set . Now if for every other element of the sequence, the i-th bit is 0, the prefix xor array(considering i-th bit only) will be 0 till (u — 1) and 1 after. If there exist some other element (say at index v) with i-th bit set, then the prefix xor array will be 0 till u — 1, 1 from u to v — 1 and 0 after v. This violates the strictly increasing property of prefix xor array. Hence there should be a unique element with a particular bit set. Now since a(i) > a(i — 1) and a(i) and a(i — 1) do not share any common bit, MSB(a(i)) > MSB(a(i — 1)).
 » 2 months ago, # | ← Rev. 2 →   what the shit u have written for div2 c. how to prove it. bsdk editorial to thik se likha kar sale. paise leta hai to thik se likhdreamoon_love_AA
 » 2 months ago, # | ← Rev. 4 →   Good contest with challenging problems!
 » 2 months ago, # | ← Rev. 4 →   great contest!
 » plz can somebody tell why this gives wrong ans? https://codeforces.com/contest/1330/submission/75438529
 » i can not understand div2 C problem correctly. can anyone help me in this plzz. the editorial is quite fast.
•  » » 2 months ago, # ^ | ← Rev. 2 →   li in i-th operation means in this operation, you can color li numbers of cells, you can start with any position as long as there are no less than li cells after this position and cells will have the color from the latest operation. So the task is to find the starting position for every operation so that you can color all cells and every colors are used at least once.
•  » » » thank you for your help. now i understand how to solve it. thank u.
•  » » » » The question states that each color must appear at least once.How many colors are there?
•  » » » thank you very much. nice problem set. specially div2 C.
•  » » » I have some issue in understanding problem Div2-CIn test case 2 2 1 2n = 2 m = 2output should be 2 1Why is it "-1"?
•  » » » » In your solution, the first color will be covered by the second color. In the end, there is only one color.
 » I loved the contest. Thank you dreamoon_love_AA
•  » » Thank you~
 » Can anyone tell what was wrong with this submission? https://codeforces.com/contest/1330/submission/75383926
•  » » for input like 1 2 1 2 3 4 ans is 2 4 from both ways by your code and each ans should be unique
 » A problem was the most wonderful problem i have seen.
 » Thanks for the wonderful tutorial,Ienjoy this competition very much ^_^
 » I liked the contest very much, but I wish the pretests can be better next time.Thank you for the round,and thanks to Denis aramis Shitov.
 » I thick that Div.1B is much more difficult than Div.1C.
•  » » Tbh I think it depends on how good you are in counting problems. I found divB easier because I'm not that good in implementing even though I had the algo for div1C
 » Could anyone explain why my 2C is wrong? Thanks! Link: https://codeforces.com/contest/1330/submission/75413150
 » What a great contest!
•  » » Thank you~
 » Why "For each i, posi=max(i,n−suffix_sum[i]+1)"?
•  » » Same question (about 2C/1A). Seems like magic — can anyone explain the intuition?
•  » » One observation is that for any valid solution we can adjust it so that if i=x.
 » How does my submission for Div2 b 75433741 get TLE, while another code 75420830, which I think has similar complexity to mine, get accepted?
 » Nice Contest！Good problems.
•  » » I'm glad that you can think so. :)
 » Can anyone tell what was wrong with this submission?problem B. checker comment:_wrong answer Integer 0 violates the range [1, 5] (test case 324) https://codeforces.com/contest/1330/submission/75450052
 » can someone please explain div2 A problem. How does this collection in first example 2 and 4 after 5 as v?
•  » » After adding 2 and 4 u can get rank 1,2,3,4,5,7,10. but largest v (where we get all ranks from 1 to v ) is 5. therefore answer is 5.
•  » » » thank u so much for helping me out. Noone helps beginners easily :)
 » 2 months ago, # | ← Rev. 2 →   Weak pretests for Div2A unfortunately :(
 » In 1330B — Dreamoon Likes Permutations , according to author solution if we give test case like size of array is 5 and array elements — {1,2,3,4,5}. Then ans is 2 0 5 5 0 But it is said the two permutations are of non-zero length. Isn't this a contradiction? Answer shoud be 0. Please correct me where I am wrong.
•  » » Please check the constraint of array element. all values are between $1$ to $n-1$
•  » » » Thanks for the correction.
 » 2 months ago, # | ← Rev. 2 →   Could someone please explain how we arrived at this formula for Div 2C? For each $i, pos_i=max(i,n−suffixsum[i]+1)$.EDIT: Formatting
•  » » See this may help with example 1330C solution with example
 » Problem B(Div2) also solvable by using the prefix sum. Here's my submission: 75458331
 » Problem B can be easily solved using rolling hash!
 » Div2-D/Div1-B, I dont't know how to solve it, but i just print the answer for the first 16 number using a program I. And I found regular pattern in it (table I). i-th row in table I is the number of every possible xor-sum of the case n = i.Observation I: $f(x)$ represents the number of the case n=x, then $f(x) = f(x-1)*2$ if x is qual to lowbit(x) where lowbit(x) means x&-x. The lowbit of 0b100100 is 0b100.Observation II: $g(x)=highbit(x)$, highbit means the highest-bit in the number. The highbit of 0b10100 is 0b1000 and the highbit of 0b11101 is 0b10000. Then $f(x) = f(x-1) + f(g(x)-1)$ if x is not equal to lowbit(x). So $f(x) = f(g(x)) + (x - g(x))f(g(x)-1)$ if x is not eual to lowbit(x).Then I write the solution by the observation. Solution in contestThanks for the fortune make me become candidate master. Program Isigned main() { map cnt; cnt = 1; for (int i = 1; i <= 16; i++) { map cnt2; for (auto &p : cnt) { cnt2[p.fi] += p.se; if ((p.fi ^ i) > p.fi) cnt2[p.fi^i] += p.se; } for (auto& p: cnt2) { cout << p.se << " "; } cout << endl; cnt = cnt2; } return 0; }  Table I1 1 1 1 1 1 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 2 2 4 4 1 1 2 2 4 4 5 5 1 1 2 2 6 6 6 6 1 1 2 2 6 6 6 6 1 1 2 2 6 6 6 6 1 1 2 2 6 6 6 6 2 2 4 4 12 12 12 12 1 1 2 2 6 6 6 6 4 4 5 5 18 18 18 18 1 1 2 2 6 6 6 6 6 6 6 6 24 24 24 24 1 1 2 2 6 6 6 6 12 12 12 12 25 25 26 26 1 1 2 2 6 6 6 6 18 18 18 18 26 26 28 28 1 1 2 2 6 6 6 6 24 24 24 24 28 28 29 29 1 1 2 2 6 6 6 6 30 30 30 30 30 30 30 30 1 1 2 2 6 6 6 6 30 30 30 30 30 30 30 30 1 1 2 2 6 6 6 6 30 30 30 30 30 30 30 30 
 » Can someone please tell me what is wrong with my submission for Div.2B? Similar idea with editorial but simpler implementation with 2 sorted vectors? My Submission: https://codeforces.com/contest/1330/submission/75460697
•  » » https://codeforces.com/contest/1330/submission/75559827 o(n) solution using 3 arrays
 » Problem D reminded me of Bookshelves. The reason it reminded me of it is because both problems require us to divide the given problem into 30 sub problems (based on the number of bits) and then solve that sub-problem with a DP. When I saw Bookshelves, I was very surprised at the idea. But introspecting about it was the reason I was able to solve this D.Here are my solutions, in case anybody wants to refer them
 » https://codeforces.com/contest/1330/submission/75403704 Getting wrong answer on B, can someone help?
•  » » you can check the 11-st test cases in test 2.What you get wrong is in the following input: 1 6 2 2 2 2 1 1 
•  » » » sorry gave the wrong link, https://codeforces.com/contest/1330/submission/75432926
•  » » » » 7 weeks ago, # ^ | ← Rev. 2 →   if the input : 1 6 1 2 3 1 2 3 the answer should be 1 3 3 your code output 2 3 3 3 3 
•  » » Your code fails when l1=l2. Then there is only one unique partition but you printed 2.
 » 2 months ago, # | ← Rev. 5 →   For Div1B sequence can be found on OEIS. This is the differences between answers for $d$ and $d+1$. Source code for python available on OEIS too in bottom of the page. I copy-pasted this code to my program and got accepted during contest. Idea to search on OEIS came to me on second hour, because I believed to author when read the statement that it can't be found on OEIS.
•  » » I think what you mean is the sequence of "distinct" differences between answers for $d$ and $d+1$. You are right. I didn't found it when I test it during preparing the contest. It shows that I still need to train myself about the ability of searching in OEIS. (>__<)
 » 2 months ago, # | ← Rev. 2 →   In Div2 D, I think there is a typo in the example of editorial. For example, when n = 6 , it should be d=6 . 'n' is the size of a matrix.
•  » » Thank you. I fix it now.
 » I think the expression of DIV2B is ambiguous. In the statement of the question："Now Dreamoon concatenates these two permutations into another sequence a of length l1+l2. First l1 elements of a is the permutation p1 and next l2 elements of a is the permutation p2."This sentence misled me into thinking that a is made up of two "permutation", but the a in the test data may be 1，2，3，4... or 1 1 1..... Obviously, in the test data, a is random, not made up of two permutation.
 » The DIV2B problem was very tricky.
 » Love how you explained the constructive algorithm in 1329A so thoroughly! I didn't find a solution in 2 hours, just as you say, the conditions are way too 'open'. Your explanation gives me new insight on how to approach problems like this.
 » 2 months ago, # | ← Rev. 2 →   dreamoon_love_AA can you please explain it more for coloring problem.There exists some i such that li+i−1>n. In this condition, at least one of the first i−1 colors will disapear after i-th operation.how to prove it.
•  » » If there exists some $i$ such that $l_i+i-1 > n \Leftrightarrow i > n-l_i+1$, the $i-th$ operation must be done at position $p_i < i$, that is because $p_i \le n-l_i+1 < i$. In this case, it will overlap other colors and make them disappear. Hope that help!
•  » » » i m not satisfied with the tutorial.What if the test case is 6 5 1 4 3 4 2As per tutorial it gives -1.But still the solution is possible as 1 2 4 2 2 which is possible.
•  » » » » 7 weeks ago, # ^ | ← Rev. 2 →   why's that, the 2nd colour and the 4th colour have the same length and the same p[i] (as you said), then the 4th colour will surely overlap the 2nd one. (or did you have a typo i think?)
•  » » » » » try to colour as i have mentioned in the answer. There will be one colour of each m which is the requirement in question.
•  » » This means that n — li < i — 1. Now, whenever you colour li blocks, exactly n — li blocks remain uncoloured. If this number is less than i — 1, it means that less than i — 1 blocks remain uncoloured after this operation. But in the previous i — 1 operation, you have put i — 1 colour and even if each of them occupies just 1 block, it will disappear after this operation.
 » what is a1,a2,...an in div 2 D / div 1 B pls explain.....
 » In Div2 problem B (1330B), i don't understand what "p+len1" mean, can anyone help me? (line 16)
•  » » p+len1 means reference to "array p at index len1" so a will point to p[len1]
•  » » » thank you very much
 » In Div2-C, how do we know that after applying "sort" constraint, our problem won't become unsolvable?
•  » » No need to sort SEE HERE
•  » » » In my opinion, the output of your solution is also "sorted".
•  » » » » In a sense yes. But great problem though ,feels good to solve this one even after contest
•  » » You won't know before you try it. That's just like We don't know whether we can solve a problem before we think out a solution. When solving problems, just like do DFS on the thought until you arrive at the correct solutions. apply "sort" constraint is just one possible try on this problem. You can also try many other things such as all $p_i$ are equal or $p_i$ is from larger to smaller.
 » 2 months ago, # | ← Rev. 3 →   For those who are facing the wrong answer on test case 2 in 1330B — Dreamoon Likes Permutations try for test cases whose l1 and l2 are equal. For example a=[1,2,2,1] or a=[2,1,2,1]. In this case, the output should be 1 2 2 and not 2 2 2 2 2 or anything similar. Click on this to view my solution.
 » 2 months ago, # | ← Rev. 2 →   Nice contest . This is how contests should be — 5 problems and 2 hrs. max . Nice , compact and standard problem statements and conducted very well . Although I believe pretests should have been stronger . This is my first comment ever and I wrote it to appreciate your commendable work .
 » Was scrolling through the comments and didn't seem to find someone giving a proof on the correctness of Div 1B/Div 2D (that is, the sequence is valid if and only if $h(a_i)h(b_k)$ for all $k\le i$: the first equality is because $b_{i+1}=a_{i+1} \otimes b_{i}$. It then follows that $b_i$ is also increasing. Now we show that $h(a_i) •  » » Why do in the final answer , we are subtracting the value obtained by -1, like I understand how we got 24 in the editorial solution but why do we subtract the value obtained by multiplication by 1 to get 23 ? Plz help. •  » » » The empty sequence is counted once in the analysis, but it's not allowed. Hence the$-1$.  » 2 months ago, # | ← Rev. 2 → 1329B - Dreamoon Likes Sequences Can someone please explain how does knowing v=0,1,2 ... solve the problem for all lengths n>=1 ?? Thanks.  » Nice problems https://codeforces.com/profile/dreamoon_love_AA  » 2 months ago, # | ← Rev. 2 → dreamoon_love_AA May I know when will the construction of Div. 1 C and E be over? I am eagerly waiting for the editorial of Div. 1 C or may I get some hint for Div. 1 C? •  » » 2 months ago, # ^ | ← Rev. 3 → I hope I can complete it this weekend. I cannot make sure what time I can complete it just like I don't know what time I can become LGM again.P.S. In fact, I'm writting it now. But my writing speed is very slow. •  » » Now Div.1 C is complete. •  » » » Thank you very much!  » Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).  » 2 months ago, # | ← Rev. 2 → My code for div 2B was O(n^2). It gave TLE on test case 3. But according to the constraints it should have worked. Please help me out if I am missing something. https://codeforces.com/contest/1330/submission/75401692 •  » » Why do you think it can work with the constraints?$O(n^2)$shouldn't work. •  » » » n=200000 n^2=4*10^10 t=10^4 In 1 second we can do 10^8 operations Constraint is 2 seconds. Hence we can do 10^16 operations. t*n^2=4*10^14. So I thought it should work. I think I am wrong somewhere. Please correct me. •  » » » » You can do 2*10^8 operations in 2s not 10^16 •  » » » » » Oh thanks! I get it now. What a stupid mistake.  » Anyone explain properly in simple language Div 2C. •  » » Try this may be helpful Solution •  » » » Can you also provide a better explanation link for Div 2D. •  » » » » Sorry But i did not solve that one yet  » Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).  » In div1.c bottom to top approach, while constructing the solution, it is said if the current value at the iterated node is not in final tree call f(). But how to prove its possible to do the operation at that node without the leaf going below height g? •  » » I had written it. Please see the tutorial carefully. •  » » » I didn't understand this part, "Then We iterate node from smallest index to the larger one. We always can determine the weight value of the iterated node, because the weight value only can be the maximum value in its subtree". Didn't we already determine value for each node while finding minimum sum? •  » » » » 2 months ago, # ^ | ← Rev. 2 → When we have chosen the weight values set$S$remaining in the final tree, according to the trait of max heap, the value of node$1$must be the largest one from$S$. And the value of node$2$must be the maximum value in the subtree of node 2 who belongs to$S$except the final value of node$1$. And so on, we can make sure all values in the final tree will be the same with the lower bound calculated by the algorithm.  » The more I hear/read about poeple's solutions to Div1C, the more I appreciate my strikingly simple solution. All authors solutions seem to me overly complicated. I call positions from$1$to$2^g-1$free initially (positions that are at least$2^g$are not considered free). I sort all elements in this heap and consider them in increasing order. Whenever I consider some value, I traverse path from its initial node to root. If there is no free element on it, I skip it. If there is one, I check whether both of its sons are not free, and if it the case then I put it there and call it taken instead of free (if exactly one of sons is free then I skip it). And that's it, very short code here: https://ideone.com/1XiSlu •  » » Wow! I appreciate your solution a lot! •  » » I tried to understand the correctness of your simple solution, but couldn't.Could you please kindly provide some proof of it? or at least any hint? •  » » » 2 months ago, # ^ | ← Rev. 3 → Lemma: A height-$g$heap is a valid final heap if and only if for every position$r$, the element$a_r$on it is originally in the subheap rooted at$r$. Proof: =>: observe that an element can only move to the position of its ancestor <=: observe that if you fix the elements left in the final heap, the shape of the final heap is unique. (largest element should be the root, and right and left subheap both have unique shape by induction hypothesis)We will prove by induction that If we place an element, it is in the correct position. If we skip an element, it is not in the optimal solution. Proof for 1. Suppose we can$a_r$on$r$but in the optimal solution there's$b_r$on$r$. If$b_r>a_r$, we can replace$b_r$with$a_r$in the optimal solution. This is still valid by our lemma, and has a better value (contradiction). If$b_r
 » Great explanation for Div-B #C.Can you please provide some more general tips on tackling constructive algorithm problems?
•  » » 2 months ago, # ^ | ← Rev. 3 →   $\min(2(v+1)−1,d)−2v+2$ mean the number of different condition that you can choose at most one number from $2v$ to $\min(2(v+1)−1,d)$. Let $x = 2v$, $y = \min(2(v+1)−1,d)$. Firstly, there are $y-x+1$ numbers from $x$ to $y$. So if you choose exactly one number, there are $y-x+1$ choices. Secondly, you must add an additional one for the case don't choose any number from the range. That's why.UPD: fixed the bug in the fomula
•  » » » Thanks for explaining this point, but I think that y = min(2(v+1)-1,d) without -2v + 2.
•  » » » Why do in the final answer , we are subtracting the value obtained by -1, like I understand how we got 24 in the editorial solution but why do we subtract the value obtained by multiplication by 1 to get 23 ? Plz help.
•  » » » » on of the 24 combinations is choosing nothing. we should remove it.
•  » » » » » Thanks for reply
•  » » » » Ohh I got it to subtract the case when array contains no element :D
 » Auto comment: topic has been updated by dreamoon_love_AA (previous revision, new revision, compare).
 » 2 months ago, # | ← Rev. 2 →   Div2D For example, when d = 6, there are 2 choices for v=0, 3 choices for v=1, 4 choices for v=2. Please someone give me all the choices for every v. Because I get it like that for v = 0 --> 1 choice : 1(1) for v = 1 --> 2 choices : 2,3(10,11) for v = 2 --> 3 choices : 4,5,6(100,101,110)
•  » » You miss the choice "don't choose anyone".
 » I was wondering if anyone could let me know what the issue with this code for problem C Div 2 is (and possibly a test case to replicate it). Running on C — Dreamoon Likes Coloring gets the wrong answer on test case 6, but the input is too long to replicate and copy. I have also tried similar types of values to this test case, but they all succeed. I do know that my answer outputs "-1" when it should be possible. I appreciate it a lot! (First time posting.) import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Scanner; public class C { public static void main(String[] args) throws IOException { Scanner std = new Scanner(System.in); int n = std.nextInt(); int m = std.nextInt(); if (m==1) { if (n == m) { System.out.println(1); } else { System.out.println(-1); } return; } BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int tmpN = n; int[] arr = new int[m]; for (int i = 0; i < m; i++) { arr[i] = std.nextInt(); } int[] postSum = new int[m]; postSum[m-1] = arr[m-1]; for (int i = m-2; i>=0; i--) { postSum[i] = arr[i] + postSum[i+1]; } int lastBlockStart = n - arr + 1; int lastBlockEnd = n; log.write(lastBlockStart + " "); //inclusive... for (int i = 1; i < m - 1; i++) { int greedyStart = (lastBlockEnd - 1) - arr[i] + 1; //place at this index if possible int greedyStart2 = postSum[i + 1] + 1; //must place at this index in worse case... int currBlockStart = Math.min(greedyStart, greedyStart2); int currBlockEnd = currBlockStart + arr[i] - 1; //ends here... if (currBlockEnd < lastBlockEnd && currBlockEnd + 1 >= lastBlockStart) { lastBlockEnd = currBlockEnd; lastBlockStart = currBlockStart; log.write(currBlockStart + " "); } else { System.out.println(-1); return; } } int currBlockStart = 1; //starts here int currBlockEnd = currBlockStart + arr[m - 1] - 1; //ends here if (currBlockEnd < lastBlockEnd && currBlockEnd + 1 >= lastBlockStart) { log.write("1"); } else { System.out.println(-1); return; } log.flush(); } } 
•  » » integer overflow
•  » » » Works now! Thanks
 » Wow dreamoon_love_AA, This editorial includes, How to approach the problems, Not just solution. Kudos to You, Thank You!.
 » Can anyone provide proof of that is stated in Div2(Problem D) editorial about h(ai) must less than h(ai+1).
•  » » I had provided the link of the proof written by a good person in the tutorial. Please see the tutorial carefully.
 » 7 weeks ago, # | ← Rev. 2 →   Can anyone please tell me what is wrong with this code for div2 B https://codeforces.com/contest/1330/submission/75668322
 » After a long time i learnt something interesting.The problemset was really nice...Thanks Dreamoon_love_AA. Please arrange such contest as many as you can.
 » I have written this code for 1330A - Dreamoon and Ranking Collection: Your code here... #include #include #include using namespace std; int main() { int t; cin>>t; while(t--) { int n, x, missing, ans; cin>>n>>x; set s; for(int i=0; i>x; s.insert(x); } set :: iterator itr; int index = 0; for(itr=s.begin(); itr!=s.end(); itr++) { index++; missing = *itr - index; if(missing > x) break; ans = *itr; } while(missing < x) { missing++; ans++; } cout<
 » 7 weeks ago, # | ← Rev. 2 →   for Div1-C i have an idea to solve it. for each node find the number of node we have to delete in its subtree from left side, since the number of node need to delete from right and left side will be equal to get perfect binary tree after all operation, lets denote it by num[i]. and maintain left[i] and right[i] to store number of nodes we have deleted in left & right subtree of node i till now respectively. now if i call required function from pos 1 then there are 4 possiblity.if(v[l]>v[r] && left[i]v[r] && left[i]==num[i]) then it has to go to right child in this case i will update the pos from where i am calling function to get perfect binary tree finally. similarly other two condition where v[r]>v[l].once it get to leaf node, i will break it and call required function from pos that we get from above function. As i am calling required function from top most possible node every time then i should get minimum possible total sum and and i will also get binary tree finally. But i am getting WA and i couldn't find such test case. Here is my submission. Can anyone tell me what is wrong in my solution Update: thanks dreamoon_love_AA i forgot to update left[i] & right[i] for all ancestor of node from where i was calling required function. If some one want to look, here it is
•  » » You get WA on this test: 4 3 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 
 » https://codeforces.com/contest/1330/submission/75732591i Dont't know that is wrong logic in my code can some one help me with div2 B problem will be much appreciated thanks
•  » »
•  » » » 7 weeks ago, # ^ | ← Rev. 6 →   its done thankyou btw i dont know about OIES
•  » » » » I don't know what's OIES either.
 » I do not understand the editorial for Div2C. Can someone explain it better?
•  » » 7 weeks ago, # ^ | ← Rev. 3 →   There are many tutorials you can search from google or in Codeforces comments(For example, here). Please see them first. I'm busy on weekdays. I will add it in the weekend.
 » Somebody please enlighten me with the Problem C insight that is slightly more intuitive!
 » Still couldn't understand div2C after reading all the explanations...
 » @dreamoon_love_AA Can you please tell where I am getting wrong in 1330B - Dreamoon Likes Permutations ?My approach is I get the prefix sum = i(i+1)/2 and the other part( total sum — prefix )also matches one such sum, I am just checking whether any no.is repeated or not as 4+3+2+1 = 4+3+3. I am checking by the logic that suppose the no.s are 4,2,3,1 then the count of them should be max of them, i.e 4. In case of 4,3,3 the count will be 3. Here is my solution...77888159
 » **Can anyone fix the bug in my code ** https://codeforces.com/contest/1330/problem/Ahttps://codeforces.com/contest/1330/submission/78094203
 » I've been trying div2 (B. Dreamoon Likes Permutations) but I'm not really sure why am I getting T.L.E could you please help me to find out ? 78243837 ... I find the maximum inside input array and check the two possible casses (len1 = ma, len2 = n- ma ... len1 = n-ma, len2 = ma)... I use a function that is intended to check if there is a permutation in the subarray bounded by the different lengths in O(n)
•  » » You declare "vi calc(MAXN + 1);" too many time.
•  » » » Thanks a lot for giving me a hand with this
•  » » » I guess I need to study more about memory handling. Thanks
•  » » » » I think the thing you must know is declaring a vector with length $N$ need time which is proportional to $N$.
 » My approach for div 2 B is little diff. i stored elements of the prefix and suffix in 2set and checked if size of set is equal to size of suffix . this will ensure that the elements are unique and also the max element should be equal to the length. though sometimes it gave segmentation fault when i tried to remove elements from the suffix set.
 » Why suffix sum is used in div 2/C. Can anyone help me with the approach ?
 » I'm trying to solve this problem B. Dreamoon Likes Permutations, and I'm getting WA on text 2 (wrong answer Participant output partition 3 3 at least two time on test 324).Here's my codeanyone can help ?