### Vovuh's blog

By Vovuh, history, 13 days ago, ,

Suddenly, all problems expect A and D were invented by me. The author of A and D is MikeMirzayanov.

1234A - Equalize Prices Again

Tutorial
Solution

1234B1 - Social Network (easy version)

Tutorial
Solution

1234B2 - Social Network (hard version)

Tutorial
Solution

1234C - Pipes

Tutorial
Solution

1234D - Distinct Characters Queries

Tutorial
Solution

1234E - Special Permutations

Tutorial
Solution

1234F - Yet Another Substring Reverse

Tutorial
Solution
WA?

• +107

 » 13 days ago, # |   +21 Fenwick appraoch for 1234D : SolutionImplementation similar to: CodeMonk ProblemAwesome contest by the way! :D
•  » » 13 days ago, # ^ |   +2 I used bitmasks and segment tree instead: 61684182
•  » » » 6 days ago, # ^ |   0 I also used a segment tree but I used sets instead of bitmasks: 62130226Apparently it is too slow... Can anyone explain why? by how much? or if it has a worse complexity time than the tutorial or other solutions?
•  » » » » 6 days ago, # ^ | ← Rev. 4 →   0 Sets would be slower by a constant-ish factor (final complexity about $O(n \log n \cdot A \log A)$), since there are at most 26 distinct letters. This could be significant, as bitwise operations are one of the fastest hardware operations that a computer can do, compared to having to clear and rebuild trees every update.
•  » » » » » 5 days ago, # ^ |   0 Thanks a lot! I have submitted it using bitmasks instead of sets. It went from more than 2 seconds to just 140ms (because ofthe constant-ish factor!): 62184825Thanks again:)
•  » » 13 days ago, # ^ |   0 Can you please tell me how you came with the intuition of using Fenwick tree?
•  » » » 12 days ago, # ^ | ← Rev. 2 →   0 From what I can tell it's the same concept as explained in the editorial, except that he's using a Fenwick tree instead of an ordered set for "does the character exist in this range" queries
•  » » » 12 days ago, # ^ |   +12 Spheniscine Correct!pyduper I am assuming you know basics of BIT :) Notice that the question wants us to find if a character exists between the range l to r. ie. for all characters from a to z if their count(l to r) > 0 or not.Which we can easily do by creating 26 BITs for every alphabet(and basically do what a BIT does) So the ans for total distinct elements between l and r would be like :  for(int i = 0 ; i < 26 ; i++){ int count = query(BIT[i],r) - query(BIT[i],l-1) ; ans += count > 0 ; } Updating BITs : Assume we need to change arr[index] to char ch what we notice here is that we have to decrease frequency in BIT[arr[index]] at index by 1 and increase frequency of BIT[ch] at index by 1 which would be like :  update(BIT[s[i]-'a'],i,-1) ; s[i] = ch ; update(BIT[s[i]-'a'],i,1) ; Also the complexity of the code would be : NlogN + 26*QlogN which is quite feasible :) Thats it!
•  » » » » 12 days ago, # ^ |   +3 Thanks.. I accidentally down voted instead of up voted. I cannot change it now. I am really sorry.
•  » » 12 days ago, # ^ |   0 funny thing that I saw a lots ppl like you, they knew a lots advanced things that I only heard about, like segment tree or fenwick tree or dp on tree, but the most important thing that you and they are the same, just only specialist. So the question I want to know that why you know a lots but you cant do anything gud in official time of a contest, and can I archive candidate master without knowing about segment tree or fenwick tree. I really need to know answer for this question, help me if you can, plz!
•  » » » 12 days ago, # ^ |   0 Well, it's just been a year since I knew about CP and if you see my rating graph I was not serious at all till april-may(mostly because I was into development at that time) so that makes about 7-8 months. If you ask me the reason the obvious answer would be lack of practice(I have just solved about 400-500 problems (mostly easy-med) over coding websites all together).looking at my graph I think I am kind of improving (maybe?)important My personal thoughts: BIT should not be considered as hard as Segment Tree (according to me a person with 1400+ rating can easily understand and implement BIT). BIT just requires 8-10 lines of code to implement. Also, I've never actually required to implement a seg tree in questions of rating < 1900 (mostly) but that's just my personal thoughts :D.
•  » » » » 11 days ago, # ^ | ← Rev. 10 →   0 My opinion is that BIT is easier to code, but harder to intuit, while segment trees are the opposite. Segment trees are more powerful (it can solve any problem BIT can, and some problems BIT can't), but BIT tends to be faster constant-wise.This problem is actually quite instructive about the difference, cause you need 26 sum-BITs, one for each character, but only one OR-segment-tree. Segment trees can work on any monoid (type/set with an identity value and an associative binary operation), but BIT has the additional requirements of the operation being reversible and commutative, hence working on + but not on OR (which is commutative and associative, but not reversible).
•  » » 7 days ago, # ^ |   0 Hi Dsxv1234DI tried with an approach similar to the one mentioned in editorial. The only difference between the implementation is: I used array of sets while they used vector of sets. Could you please tell me what's wrong with my solution: 62051065
•  » » » 7 days ago, # ^ |   0 I think the 'lower_bound' in your code is working in linear time. Just replace it with ( it = contain[i].lower_bound(l) )
•  » » » » 6 days ago, # ^ |   0 Thanks AV7, it was the culprit, now I got AC. But can you tell me why those two are not of similar complexity?
•  » » » » » 6 days ago, # ^ |   0 You will find the answer here
 » 13 days ago, # | ← Rev. 3 →   +1 My solution to E: https://codeforces.com/contest/1234/submission/61676673Just consider how the distance of each pair in the array changes in permutations.Let the smaller number in the pair be m and the other be n;The distance increases by m-1 when i=m because m goes to the front and the distance increases 2m-n when i=n because n goes to the front and m shifts 1 backwards. For i from m+1 to n-1 the distance simply decreases 1 because one of the number between them goes to the front.I hope my explanation makes sense as English is not my first language:D
•  » » 6 days ago, # ^ |   0 can you please elaborate?
•  » » » 5 days ago, # ^ |   0 In the first to (m-1)th permutations the distance between m and n is constant. In the (m)th permutation, the number m goes to the front of the permutation so the distance increases by m-1. In the (m+1)th to the (n-1)th permutations, one of the number between m and n goes to the front so number m shift one unit back thus their distance decreases by 1. In the nth permutation the number n goes to the front while number m stays in the position of m+1 so now their distance is m+1-1=m. The distance used to be n-m so the change of the distance is m-(n-m)=2m-n In the rest of permutations, their relative position is back to normal so the distance doesn't change.Does this make sense?
•  » » » » 4 days ago, # ^ |   0 yeah totally, thanks a lot :)
 » 13 days ago, # |   +6 Weak Example in F makes me WA on 5........ I want strong example QAQ (sorry to my poor English :D
 » 13 days ago, # |   0 How can we do C with dfs?
•  » » 13 days ago, # ^ |   -13 You will TLE
•  » » » 13 days ago, # ^ | ← Rev. 5 →   +9 C can be solved by dfs by building a graph like this: and check if there is a path.
•  » » » » 13 days ago, # ^ |   0 Can you please explain how to do it with dfs with proper code and explanation?
•  » » » » » 12 days ago, # ^ |   0 look at this code https://codeforces.com/contest/1234/submission/61647685
•  » » » » » 12 days ago, # ^ |   0 I got accepted with dfs, the ideia is basically what MZuenni said:Firstly you make two types of edges, {1, 2} and {3, 4 ,5 ,6}, and you can see that with edges {1, 2} you can only continue on the line that you are, going to the next column, and with edges {3 ,4 ,5, 6} you go to the next column changing your line (see the picture above).If there is a path, then there is only one of them, by the "nature" of the edges, so the complexity is O(n).Here is my submission: 61677625, hope to be clear enough.
•  » » » » » 12 days ago, # ^ |   0 C.Pipes using BFS/DFS-- Simplify given strings into just 1s and 3s. Create a directed graph If it's a 1-pipe, add an edge from i to i+1 (Don't add for end of row1) If it's a 3-pipe (in both rows for that column),connect it diagonally from row1 to row2 or row2 to row1. (Don't add for end of row2) Use BFS/DFS to check if 2*n+1 th node is visited or not Python implementation-- https://codeforces.com/contest/1234/submission/61743877
•  » » 12 days ago, # ^ |   0 u can use dp also.taking care of direction in which water is coming(horizontal-0,vertical-1),x and y co-ordinates. u can refer to this submission
 » 13 days ago, # |   0 It is obvious that because of dynamic programming we need to remove at most one bit from our mask to cover all possible submasks that can update our answer. What is this means ？
•  » » 13 days ago, # ^ |   0 Now I understand it , becasue some dp[mask] may not init
 » 13 days ago, # |   0 I did the testing for F and found out few Test Cases. Surprisingly the WA code when ran on custom innovation, It gives same answer as that or correct code, But when it's executed locally or on some other online Compiler(other CP sites like codechef), the WA program fails on following Test Cases. Test Cases Where WA should failTest case Correct_O/P O/P_of_WA Codeobgtjbtlfbdmqksnq 12 10pbfpdqlqsptfq 7 6jlotbnjqoeqqll 8 7dtrdlfighqlikdad 10 9Though If anyone finds the reason behind the behaviour of WA code in Custom Innovation, do let me know. I'm quite curious about this.
•  » » 12 days ago, # ^ |   +11 That's because CLOCKS_PER_SEC in codeforces is 1000, but in other compiler (I used Dcoder) is 1000000. So clock() gives microseconds. Instead you should set , (clock()-tt) > (1.90)*CLOCKS_PER_SEC).
 » 13 days ago, # |   0 My code for problem C. https://codeforces.com/contest/1234/submission/61656247 Can anyone help me with that? I considered that the number of 3,4,5,6 type pipes should be odd and if a pipe is of 3,4,5,6 type in one row,it should be of the same type in the corresponding index of the other row.
•  » » 13 days ago, # ^ |   0 Leave it,got the error
 » 13 days ago, # |   +3 I also applied segment tree approach 61686336. But it's giving TLE. Can anyone please tell me where I went wrong?
•  » » 13 days ago, # ^ | ← Rev. 2 →   0 @gaurav_iiitian check my code I used segment tree and it got accepted. My code was easy to understand..
•  » » » 12 days ago, # ^ |   0 Thanks @dhruv_garg for replying, But I think our implementations are almost same. The only difference being I coded in python. I think codeforces hasn't set time multiplier for python since my code is giving TLE in just 2s which should be 10s for python. @admin look into this please. I'm really disheartened to see this in codeforces and it's my early days here.
•  » » » » 12 days ago, # ^ | ← Rev. 4 →   +1 Same story, but I did it after contest by adding some optimizations. Firstly I used bit representation for each char: 'a': 1, 'b': 2, 'c': 4. We have an alphabet with size of 26. So 'z' is 2^25. And if you want to know the sum, you just do bitwise OR (Node1 | Node2). Then I precalculated bit representation for every char and stored it in the dictionary. I added the popcount function (https://stackoverflow.com/questions/407587/python-set-bits-count-popcount) for [l, r] requests. Python got TL on 9th test, but PyPy got AC with 1980 ms. Here is the submission 61730030. Hope it will help.
•  » » » » » 12 days ago, # ^ |   0 Nice approach, I got TLE once during contest and after that many times. I stored all the characters in a dictionary of 26 keys where we can directly check which of the character is present or not (count==0). But yours might do better since xor is better than (looping 26 times). Mine gave TLE on test case 13 on PyPy. I'm really hopeful that moderators and admins take a note of this and in future this don't happen.
•  » » » » » » 12 days ago, # ^ |   0 Gaurav, here's an AC for your code...https://codeforces.com/contest/1234/submission/61749881Use Fast I/O in PyPy3Just add input = sys.stdin.readline
•  » » » » » » » 12 days ago, # ^ |   0 Thanks @thecodearrow, that would do. Although I think python multiplier should have been set there.
•  » » 12 days ago, # ^ |   +1 I also got TLE when I implement segment Tree with Python...@admin please have a look at this..
 » 13 days ago, # |   +3 I used approach of tutorial D. Can someone please explain why lower_bound(s[i].begin(), s[i].end(), l) is getting TLE but same solution with s[i].lower_bound(l) instead, not? Only difference is way of using lower_bound.
•  » » 13 days ago, # ^ |   +1
•  » » » 13 days ago, # ^ |   0 Thanks a lot. Understood the reason.
 » 13 days ago, # |   0 Why does ceil(double(sum)/n) give a wrong answer on but (sum+n-1)/n doesn't.
•  » » 13 days ago, # ^ |   0 refer this thread, https://codeforces.com/blog/entry/70185?#comment-547110
•  » » 10 days ago, # ^ |   0 Maybe the return of ceil was in the form of double so your answer was printed out as 5.234e4 intead of 52340. assign to int before printing
 » 13 days ago, # |   0 can someone help in finding issue in this code https://codeforces.com/contest/1234/submission/61661254. it's failing on 1 test case on codeforces compiler. but locally it passes
 » 12 days ago, # |   0 Can anyone tell me why I got TLE by using char instead of string in problme D?(I used the same approach as the tutorial, I switch char to string then it got accepted)
 » 12 days ago, # |   -8 Well. I have a deterministic solution for F. Vovuh I don't know where your solution will break. But intuition is not coming. My approach:dp[mask][len] will store maximum starting index for all the submask of mask with length len. then we can simply find the answer for it's complement for all length. link to my solution:61694665
•  » » 12 days ago, # ^ |   +13 As you can see, my main solution is deterministic too (and it solution is described in the editorial). Moreover, my second (possibly WA) solution is also fully determined (except the order of masks with the same number of ones).
•  » » » 12 days ago, # ^ | ← Rev. 2 →   0 Vovuh I don't understand how you are making sure that the mask will not override...UPD: got it. silly me. Thanks
 » 12 days ago, # |   +1 Damn slow python... Got TL with Segment Tree
•  » » 12 days ago, # ^ |   0 I also got TLE when I implement Segment tree in D problem ...I guess they did not give enough time for python
•  » » » 12 days ago, # ^ |   0 Use Fast I/O in Python input=sys.stdin.readlineand Submit it using PyPy3Refer this to get an AC-- https://codeforces.com/contest/1234/submission/61749285
•  » » » » 11 days ago, # ^ |   0 I already use Fast I/O and I tried it in PyPy3 ... but actually I got my mistake there was no problem of time given
•  » » 12 days ago, # ^ |   +3 For extra masochism, try solving heavy bitmask problems with JavaScript :P
 » 12 days ago, # |   0 Very Nice Explanations and Clear Editorials.
 » 12 days ago, # |   +3 I wonder why I got TLE in pronlem D when using Segment Tree......(61656622)(sorry for my poor English x(
 » 12 days ago, # | ← Rev. 2 →   0 My solution got tle in D in system testing and the same solution is accepted on submitting after System testinghttps://codeforces.com/contest/1234/submission/61710080https://codeforces.com/contest/1234/submission/61641496
•  » » 12 days ago, # ^ |   +3 Your accepted solution took 1996ms which is too close to limit of 2s. difference of few ms in runtime can happen due to various factors.
•  » » » 12 days ago, # ^ |   0 Thanks
 » 12 days ago, # |   0 I think this is not as simple as before
 » 12 days ago, # | ← Rev. 6 →   0 unordered_set let me down on B2 :(Nice tests!This post helps, in case anyone who used unordered_map or unordered_set needs it.
 » 12 days ago, # |   0 After the contest I tried to write B2 with STL deque,but when I use unordered_map it got TLE but map got AC.In my previous conciousness map should be slower than unordered_map,what's wrong with unordered_map in B2?The unoredered_map version TLE:61711501The map version AC:61711675
•  » » 12 days ago, # ^ |   0 unoredered_* very slow if hash function have a lot of collisions. Author know stl implementation of hash function and generate special tests. Map (non unordered) is a tree and have determine time of work.
•  » » 12 days ago, # ^ |   +6 You can read thisIf you use unordered_map, your time complexity may up to O(n).(and, sorry to my poor English
 » 12 days ago, # |   0 SquareRoot Decomposition approach for D: 61667541
 » 12 days ago, # |   0 Need help in this. https://ide.codingblocks.com/s/137727 for problem D this solution is getting WA for test case 2 https://ide.codingblocks.com/s/137726 I just switched line 91 and 92 got AC for all the test cases. Why am i getting this. I created 26 sum query segment trees and for every alphabet if the sum of segment is greater than 0 then there is that distinct character in it and I increased the answer for that query. Why does swapping two line get me WA?
 » 12 days ago, # |   0 For B2:Changing from unordered map to map gave AC. The unordered map is faster than the map then why did I get TLE?Thanks.
•  » » 12 days ago, # ^ |   0
•  » » 12 days ago, # ^ |   0 You can read this.
•  » » 12 days ago, # ^ |   0 unordered_map is not always faster, you can read the mentioned post in the comments above.
 » 12 days ago, # |   0 Hey Comunity! I am getting TLE in problem 1234B2 for test case 23. Can someone please help me? my sol
•  » » 12 days ago, # ^ |   0 Changing from unordered_set to set gave me AC. Never seen this scenario.
•  » » 12 days ago, # ^ | ← Rev. 2 →   0 Explanation why std::set works.
 » 12 days ago, # |   0 I dont think prob E is a 2000-difficulty problem, just like a 1700 or 1800 problems in a div2 contest. I also saw a quite easy task in another div3 before that had 1900-difficulty. I feel weird when there are a lots overrating problems in div3, so I wonder how ppl rate difficulty for problems
•  » » 12 days ago, # ^ |   0 Yeah that's true. It's probably because many high rated coders just solve the last problem and leave the contest. And the algorithm thinks they couldn't solve that problem. I am not sure about this. I am just guessing
•  » » 12 days ago, # ^ |   0 Problem rating are decided by relativey how many official contestants mangage to solve it during live contest. Majority of people do not get time to even read last 2 questions hence they could not solve. Ultimately, that leads to over-rating.
 » 12 days ago, # |   0 Anyone can explain why using std::set gets AC but gp_hash_table (policy based data structures)(https://codeforces.com/blog/entry/60737) gets TLE? I'm very confused.AC: 61716953TLE on test 20: 61712878
•  » » 12 days ago, # ^ |   0 dont use hashtable, its overkill in this case, and also hashtable sometime is not a gud choice because of hacks. Consider using a deque instead, this task is all about how to work with a double end queue and nothing else
•  » » » 12 days ago, # ^ |   0 Yeah, i just used hash table to check if elements existed in queue or not.But I can not understand why set + deque = AC but gp_hash_table (as I know it's 4x faster than normal std::map) + deque = TLE. It's weird.
•  » » » » 12 days ago, # ^ |   0 I am not sure but what he mean is that it can be hacked. refer this blog
 » 12 days ago, # |   0 I used a segment tree for problem D. I tried the segment tree that had unordered_map(61658230),set(61650912) and map(61656330) as elements of its nodes but all three showed TLE. Can anybody help me figure out where is the mistake in my code.
 » 12 days ago, # |   0 As C have only 2 input strings, I zipped them, and used regex with eval, analyzing pairs of symbols (columns). An alternative to if-else blocks. Perl code 61668008 (or shorter without zip: 61669016)
 » 12 days ago, # |   -8 can anyone explain why it TLE on b2 https://codeforces.com/contest/1234/submission/61635087 I think complexity is best possible
 » 12 days ago, # |   +3 Alternate approach for E, any two consecutive elements of the array x and y contribute abs(x-y) to all f(pi(n)) where i is less than min(x,y) or when i is greater than max(x,y). x and y contribute abs(x-y) -1 to all f(pi(n)) when i lies between x and y.Using a Segment tree with lazy propagation we can do the above contributions/range updates for all pairs of consecutive elements. Answers will be the ranges i,i for i: 1 to nHere is the code : https://codeforces.com/contest/1234/submission/61666909
 » 12 days ago, # |   -8 In problem B1 and B2 i have used Dequeue and Unordered_Set, these are my solutions:-(both are same) B1:- link B2:- linkunordered_set should work more efficiently than set as per time complexity, but in B2 i got TLE on Test Case 23 , after changing unordered_set to set i got AC:link Please anyone explain me why this happen? and also how should i select set (i.e unordered_set/set) while solving any similar problem in future!!Thanks!
 » 12 days ago, # | ← Rev. 2 →   0 In problem E, I have this stupid question which I cannot figure it out on my own -_- .In the code provided above: for (int i = 1; i < n; ++i) { res[i] = res[0] - cnt[i]; for (auto j : adj[i]) { res[i] -= abs(i - j); res[i] += j + (j < i); } } So why res[i] += j + (j < i) here. I thought when we move the element i to position 1 then the cost should be res[i] = j-1 + (j < i), shouldn't it?Thanks in advance <3
•  » » 12 days ago, # ^ |   +3 I don't sure my answer what exactly do you mean but if I understood you correctly, that's because $i$ and $j$ are $0$-indexed in the code.
•  » » 12 days ago, # ^ |   0 He has decremented values of a[i] initially that's why res[i]=j+(j
 » 12 days ago, # |   +1 Problem D: I implemented editorial's solution in JAVA. For that I had to use TreeSet for lowerbound() function. Here's my JAVA code: 61727406
 » 12 days ago, # |   +1 Can somebody explain me problem F's soln? Sorry but i am unable to understand the editorial?
 » 12 days ago, # | ← Rev. 2 →   0 can someone
 » 12 days ago, # |   0 Need DP idea of Problem C.
•  » » 11 days ago, # ^ |   0 check out my submission
 » 12 days ago, # |   0 C.Pipes using BFS/DFS-- Simplify given rows into just 1s (1,2=1) and 3s (3,4,5,6=3). Create a directed graph If it's a 1-pipe, add an edge from i to i+1 (Don't add for end of row1) If it's a 3-pipe (in both rows for that column),connect it diagonally from row1 to row2 or row2 to row1. (Don't add for end of row2) Use BFS/DFS to check if 2*n+1 th node is visited or not Python implementation-- https://codeforces.com/contest/1234/submission/61743877
 » 12 days ago, # |   0 can anybody explain, what does this mean ? "Let dp[mask] be the maximum number of ones in some mask that is presented in the given string and it is the submask of mask" , here what does the submask of mask mean?
•  » » 12 days ago, # ^ |   +3 The submask has fewer or equal number 1s than the mask and the position of all the 1s in submask coincide with the 1s in mask (the mask includes the submask)For example : 010011 is the submask of 011011This is my opinion so correct me if I'm wrong <3
•  » » » 11 days ago, # ^ | ← Rev. 3 →   0 can you please explain how the submask is helping in dp , I have understood till the point in editorial that we have to find two non-intersecting mask in the string and the one of the pair with max sum from both mask will be answer, but I can't understand beyond because of not able to understand the role of submask in dp further from here.
•  » » » » 11 days ago, # ^ |   +1 if (dp[mask] == __builtin_popcount(mask)) { int comp = ~mask & ((1 << 20) - 1); ans = max(ans, dp[mask] + dp[comp]); } So the point the submask is important is : $dp[comp]$ will be the maximum number of 1s from all the submasks of $comp$ (include the mask $comp$ as well) We don't know if the " $comp$ " mask is really present in the string or not, so we need to take the max of the submasks so that it is added to the answer. For example: $mask$ is ...100110 ( $dp[mask] == __builtin_popcount(mask)$ ) --> this ensures the mask is present somewhere in the string) (...bcf...) --> $comp$ is ...011001 ($comp$ may or may not present in the string). So if we don't take the max of the submasks then $dp[comp]$ will be 0 then. But let suppose there is a substring (which is a submask of $comp$) ...010001 (...ae...) then $dp[comp]$ will be >0 (say, 2) and the answer is larger.P/s: if $comp$ doesn't intersect with $mask$ so the submasks of $comp$ doesn't also
 » 12 days ago, # |   +1 Didn't understood the tutorial of E could someone pls elaborate on making prefix arrays.
•  » » 11 days ago, # ^ | ← Rev. 4 →   0 My approach is somewhat different:Let $F_j$ represent the $j$-th answer value, i.e. $f(p_j(n))$.Now consider each consecutive pair in array $x$, i.e. $x_i$ and $x_{i+1}$. We want to consider this pair's "contribution" ($|pos(p_j, x_i) - pos(p_j, x_{i+1})|$) to the final values in $F$. Let the smaller of the pair be $l$ and the greater be $r$ (if they are equal, their contribution to all values of $F$ are zero, so we can skip it)It turns out that we can split these contributions to five regions: for indices $j < l$, we want to add $r-l$ to $F_j$, for index $j = l$, we want to add $r-1$, for indices $l r$, we want to add $r-l$. Now the problem reduces to the "Array Manipulation" problem from HackerRank, i.e. we need to find a way to efficiently add values to entire ranges of indices. It turns out that there's a simple solution: instead of working on the final array $F$, we work on another array $D$ instead, where we want the eventual value of $D_i$ to equal $F_i - F_{i-1}$. We can then extract $F$ from $D$'s prefix sum.So if we want to add e.g. value $x$ to $F_{a..b}$, simply add $x$ to $D_a$, and subtract $x$ from $D_{b+1}$.Sample code (Kotlin): 61688222
•  » » » 11 days ago, # ^ | ← Rev. 2 →   0 How did you come up with those five contributions ? Edit: Nevermind, that's simple observaton. Got it.
 » 11 days ago, # | ← Rev. 2 →   0 Problem A can also be solved using binary search :: Solution : https://codeforces.com/contest/1234/submission/61633785
•  » » 11 days ago, # ^ |   0 but its not need
 » 11 days ago, # |   0 【Problem E】 I did not understand what tutorial says. please tell me what cnt[min(x[j],x[j+1])+1] and cnt[max(x[j],x[j+1])] stands for.
•  » » 11 days ago, # ^ |   0 Because all the number from $min(x[j],x[j+1])+1$ to $max(x[j],x[j+1])-1$ will have their presence increase by 1 so $cnt[min(x[j],x[j+1])+1]++$ and $cnt[max(x[j],x[j+1])]--$. From the number $max(x[j],x[j+1])$ till on doesn't increase so we decrease 1 at $cnt[max(x[j],x[j+1])]$
 » 11 days ago, # | ← Rev. 2 →   0 Has someone solved D with a segment tree with bitmasks, or am I alone dumb?
•  » » 11 days ago, # ^ |   0 If you mean problem D, yes I did it that way too (after contest time though, cause the contest time wasn't convenient for me, but I solved it blind)
•  » » » 10 days ago, # ^ |   0 Lol, I forgot write problem which I meant, anyway thx for answer
 » 11 days ago, # |   +3 F. Yet Another Substring Reverse ( with explanation )Check out my solution for more detailed explanation : 61824886
•  » » 9 days ago, # ^ |   +3 Thanks a lot :) Great Explanation!
 » 8 days ago, # | ← Rev. 3 →   0 Can anybody help me with the problem C though my approach is similar to tutorial given Here's my code: https://codeforces.com/contest/1234/submission/61957647
 » 8 days ago, # |   0 what is __builtin_popcount??? i don't know it
•  » » 5 days ago, # ^ |   0 it counts the set bit in a number
•  » » » 5 days ago, # ^ |   0 ohh thanks very much you are so nice
 » 8 days ago, # | ← Rev. 2 →   0 great tutorial!
 » 5 days ago, # |   0 F is beautiful problem
 » 4 days ago, # |   0 In problems like C, we can take input in two ways, a string input or (int or char) input in array? I'd like to hear advice on what should be used in such cases? Is string input faster than array inputs in C++? How dose C++ take string input internally? Does it also create an array first and store characters in that array? Thanks :)
 » 4 days ago, # |   0 I have a question about pipe. In the context we could reasonably assume that the we are searching in 0th pipe and 1st pipe. If we encounter 3,4,5,6, we will make cur = !cur or cur ^= 1 The logic is simple, but when I tried to use an array of dimension 2 x n, the test 2 is always failed. Then I switched to string array dimension of 2, by the same algorithm, my answer was accepted. What is the difference?
 » 3 days ago, # |   0 1234B2 can be solved in linear time (O(n)), using BITSET: https://ideone.com/W1jsgi