### pikmike's blog

By pikmike, history, 2 weeks ago, translation, ,

Tutorial

1288B - Yet Another Meme Problem

Idea: Roms

Tutorial
Solution (Roms)

1288C - Two Arrays

Idea: BledDest

Tutorial
Solution (Roms)

1288D - Minimax Problem

Idea: BledDest

Tutorial
Solution (BledDest)

1288E - Messenger Simulator

Idea: Ne0n25

Tutorial
Solution 1 (pikmike)
Solution 2 (pikmike)
Solution 3 (pikmike)

1288F - Red-Blue Graph

Idea: BledDest

Tutorial
Solution (BledDest)

• +69

 » 2 weeks ago, # |   +28 Thanks for the nice editorial. And , Actually am not able to understand how combinatorics is right to use and how it is applied for the Problem C . And also some have solved it using dp , i dont understand that approach eitherSo, can anyone please help me with my above stated problem.Thanks in advance
•  » » 2 weeks ago, # ^ |   0 combinatorics — if you have n identical object and r different object number of ways of arrangement is (n+r-1) C r-1 or n+r-1 C nnow in these question n=2*m and r=n and now total number of distribution is (n+2m-1)c(2m) and each distribution can be arranged in ascending order in one way (assuming all boxes identical for one movement and then which ever combination is there u have one way of arrange them in ascending order)
•  » » » 13 days ago, # ^ |   0 In your first two lines, for how many places you are arranging n identical objects and r distinct objects??
•  » » 2 weeks ago, # ^ | ← Rev. 2 →   +32 For combinatorics solution of C, we need to find number of non decreasing sequences of length $2m$ with values between $1$ and $n$.We can convert this problem as follows ( since we want non decreasing values ).Let $x_{i}$ denote number of times we take value $i$ in our sequence. Clearly $x_{i} >= 0$. Also,$x_1 + x_2 + x_3 + ... + x_{n-1} + x_{n} = 2m$.The number of solutions to this is given by, $\binom{n+2m-1}{n-1} = \dfrac{(n+2m-1)!}{(n-1)!(2m)!}$. You can read more about Stars and Bars.
•  » » » 12 days ago, # ^ |   +1 Those who haven't understood after reading Stars and Bars what should they consider star and what should they consider bar they can just assume all the position of an array as balls (so we got 2*m ball, right? ) and list all the numbers from 1 to n (inclusive) and think every number as container or a box. So when you are putting a ball in a box the ball will automatically get the number of the box on it. And you can put as many ball as you want in a box.so every time we will use all balls and will get different combination from it. And obviously there will be a single permutation for a combination for which after collecting all the balls from the containers(or box!) we can sort them in non-descending order according to their number. :DPretty easy, huh? :3
•  » » » » 3 days ago, # ^ |   0 problem i am facing is there might be two sequence whose sorted arrangement produce same result so how can we consider both the sequence as both are same only because we are interested in final sorted sequence. it would be very helpful if someone can explain me this
•  » » » 11 days ago, # ^ | ← Rev. 2 →   0 how can we directly use x1+x2+x3+...+x(n−1)+xn=2m or Stars and bars Theorem here ? isnt there is a condition that the array must be non decreasing sequences ?
•  » » » » 11 days ago, # ^ |   0 The question given in $C$ is equivalent to "choosing non decreasing sequence of length $2m$ with values between $1$ and $n$".Proof: If we obtain two sequences, $a,b$ that satisfy conditions given in question $C$, then we have $a_1 <= a_2 <= .... <= a_{m-1} <= a_{m} <= b_{m} <= b_{m-1} <= .... <= b_2 <= b_1$.Conversely, if we have a sequence of $2m$ elements, $s_1 <= s_2 <= .... <= s_{2m-1} <= s_{2m}$, then we can make arrays $a,b$ as $a=(s_1, s_2, ..., s_{m})$ and $b=(s_{m+1}, s_{m+2}, ..., s_{2m-1}, s_{2m})$.
•  » » » » » 11 days ago, # ^ |   0 Yeah i understand that but my question was as my array must be non decreasing sequences how can i directly use Stars and bars theorm ? isnt that theorm is just randomly choosing repetedly element ?
•  » » » » » » 11 days ago, # ^ | ← Rev. 3 →   0 Oh. Choosing a non decreasing sequence of length $L$ with elements taking $D$ distinct values can be modeled as follows.Sort the $D$ distinct values. Number them from $1$ to $D$. Let $x_i$ denote number of occurrences of $ith$ element that we take in the sequence. Then we need $x_i >= 0$, and $x_1 + x_2 + .... + x_{D-1} + x_{D} = L$Think of it like this, there are $L$ blank balls in a row, and you need to make $D-1$ vertical separators between them, and then in $ith$ segment write value of $ith$ number on all the balls, this gives a sequence that we require. Two separators can coincide too, so that means we don't take some element at all.
•  » » » » » » » 10 days ago, # ^ |   0 got it..thank you very much
•  » » » » » » » 10 days ago, # ^ |   0 awesome explaination
•  » » » 4 days ago, # ^ | ← Rev. 2 →   0 .
•  » » 2 weeks ago, # ^ |   0 I can explain my approach, which involves combinatorics, hope you will find it helpful. In the problem it is stated that the first array is non decreasing, while second array is non increasing, so, for the first array, if you set any element at the rightmost index, then every element left of it will be less than or equal to that element. Similarly, in the case of second array, if you set any element at the rightmost index, every element left of it will be greater than equal to the rightmost one. Now, suppose i is the rightmost element of first array, and j is the rightmost element of second array, we can set all values from 1 to n in this manner for i=1 to n do: for j=i to n do:Now, whatever will be the value of i, all values left of it will be less than or equal to it so, we need to select the values from 1 to i, and after selecting them, put the in non decreasing order, so, you can imagine that as solving equation: x1 + x2 + ... + xi = m-1 for non negative integers.Same goes for j, we need to solve for non negative integers, the equation xj + ... + xn = m-1. You can solve this using multinomial theorem, and will get the desired result.
•  » » » 2 weeks ago, # ^ |   0 why you put x1 + x2 + ... + xi = m-1 ?? i think number of elements is m-1 not the sum of elements is m-1.
•  » » » » 13 days ago, # ^ |   0 Because the values would be less than equal to i. Suppose i is 2 and m is 3, we can have the following combinations: 1 1 ( x1 = 2, x2 = 0) 1 2 ( x1 = 1, x2 = 1) 2 2 ( x1 = 0, x2 = 2)
•  » » 2 weeks ago, # ^ |   +4 Have a look here for Combination with Repitition: https://sites.math.northwestern.edu/~mlerma/courses/cs310-05s/notes/dm-gcomb.
•  » » 2 weeks ago, # ^ |   +3 Consider the non-descending sequence given in the editorial. It's a sequence of $2m$ elements, all between $1$ and $n$. The number of ways of building a sequence like that is the answer for our problem. We just need to figure a way of calculating it. So, basically, picking $r$ elements from a set of $n$ elements (with replacement, because we can select the same number more than once).Imagine that, since you are replacing elements, you are "adding" new ones to the set. Each of the $r$ elements we pick is replaced, except for the last one. In total, $r - 1$ replacements. The formula is ${n + r - 1 \choose r}$. In this case, $r = 2m$ (amount of elements to pick). Finally, ${n + 2m - 1 \choose 2m}$.
•  » » » 11 days ago, # ^ |   +1 Your approach of thinking for this problem of combination with replacement seems interesting. However I dont fully understand why that works. Or you can say I'm not able to get this intuition. Can you explain more?I only know how to understand this using the stars and bars method.
•  » » » » 11 days ago, # ^ |   +3 The problems are equivalent! I picked $2m$ elements from a set of $n$, with repetitions, right? That's because I considered the sequence of length $2m$. What if I only considered the amount of times I picked an element, i.e their frequency?Let's call $freq_i$ the amount of times I picked the $i$-th element. It's easy to see that $freq_1 + freq_2 + ... + freq_n = 2m$. Because $2m$ is the length of the first sequence.Now, the question is: how many solutions does this equation have? Any solution can be arranged into two arrays that satisfy the original problem statement. The stars and bars problem will give us the answer: amount of ways to distribute $r$ identical objects among $n$ distinct containers. Here, $r = 2m$. Finally, the formula is (still) $n + 2m - 1 \choose{2m}$!Take a look at this comment. The link he posted shows some other problems that are equivalent to stars and bars.
•  » » » » » 11 days ago, # ^ |   +1 Thank you for the reply. I am sorry I should have asked my question properly. I already understand how the stars and bars problem relates to solving the problem of combination with replacement.What I am interested in understand is how you used the intuition of "adding new elements to the set" to consider replacement. i.e. your lines -- Imagine that, since you are replacing elements, you are "adding" new ones to the set. Each of the r elements we pick is replaced, except for the last one. In total, r-1 replacements.So how does this "adding to the set" thing works to fulfil the replacement issue?
•  » » » » » » 11 days ago, # ^ |   0 This is just a trick to easily remember the formula. It isn't necessarily right. You can find more explanation here.
•  » » 2 weeks ago, # ^ | ← Rev. 2 →   +5 DP Approach:Consider 2m places to be filled by numbers of range 1 to n and suppose we are at index i and value at (i+1)th index is x so the max value of all the indices less than/equal to i will be x.Now, we have two cases1) Assign value of x to ith index and find answer for i-1 places for values in range ( 1 , x ).2) Find answer for i places for values in range ( 1 , x-1 ).Base cases:1) when number of places left is 1 answer will be n (fill it with values from 1 to n).2) when max value can be 1 answer will be 1 (fill all places with 1).Recurrence relation num(x,m) = num(x,m-1) + num(x-1,m)
•  » » » 11 days ago, # ^ |   0 Can you please explain how this approach , helping in maintaining the condition of Ai<=Bi ?
•  » » » » 9 days ago, # ^ |   0 When we are reducing number of choices from x to x-1 we are eliminating the highest number thus filling remaining positions with smaller numbers.
•  » » » » 8 days ago, # ^ |   0 Because the question is equivalent to finding a non-decreasing sequence of length 2m where each value lies in [1, n]. So, instead of thinking in terms of two arrays A and B, we now only think in term of a single array and this single array has to satisfy two conditions. i.e. it should be of length 2m and has every value in the range [1, n].
•  » » 13 days ago, # ^ |   0 You can understand it in this way :- As the sequence is non decreasing we can say that sequence will be like there will be some 1's (greater than or equal to zero) then some 2's then 3's and so on.. upto n. So now we have to divide the whole sequence into n parts where size of each part can be greater than or equal to 1.Suppose parts are saparated by lines then there will be n-1 lines hence now we simply have to select n-1 positions from 2*m+n-1 places which is C(n+2*m-1,n-1).Sorry for bad english.
 » 2 weeks ago, # |   +4 I think i have a better solution for A If not, please let me knowhttps://pastebin.com/SjQMG52P
•  » » 2 weeks ago, # ^ |   0 if( (n/2) + ceil(double(d) / double( (n/2) +1 )) <=n){ cout<<"YES"<
•  » » 2 weeks ago, # ^ |   +2 can you explain the approach behind it?
•  » » 2 weeks ago, # ^ |   +5 So nice solution. And here is the explanation.
•  » » » 13 days ago, # ^ | ← Rev. 2 →   0 How do you get rid of the ceil function?
•  » » » » 13 days ago, # ^ | ← Rev. 2 →   +3 x + ceil(d/(x+1)) can also be written as ceil(x + (d/(x+1))). For ceil(x + (d/(x+1))) <=n, x + (d/(x+1)) <=n holds.Very Nice solution.
•  » » » » 13 days ago, # ^ |   0 I think it doesn't matter if it's ceil or floor as long as there's a solution for x. If there's a solution for x, both ceil and floor will work for this problem.
 » 2 weeks ago, # |   +16 Persistent segtree in E is mle.
•  » » 2 weeks ago, # ^ |   +40 Unfortunate
•  » » 12 days ago, # ^ |   0 I managed to fit persistent segment tree (PST) in MLIn my solution there are at most 6*10^5 update queries to PST. Moreover, every query creates O(log) new vertexes and one vertex need 3 integers (it's 12 byte). So, PTS requires 6*10^5*20*12 = 144 MB < 256 MB
•  » » » 12 days ago, # ^ |   0 I dynamically allocated memory hence each node had an integer and two pointers. But that exceeded memory. Probably i should statically allocate all memory next time.
 » 2 weeks ago, # | ← Rev. 2 →   0 How to solve D using graph?? (There is graph tag in question!!) if anyone could provide any submission link using graphs that would be very helpful for me,thanks in advance.
•  » » 2 weeks ago, # ^ |   +12 Create a graph where each node is a number from $0$ to $(2^m) - 1$. There is an edge between $u$ and $v$ ($u \leq v$) if and only if (u & v) == u. This way, you can go from one bitmask to every other comprehended inside it.When binary searching the answer, for each array on the input you should compute two bitmasks. Let's call them $G_{msk}$ and $L_{msk}$. If you are currently trying answer $x$, then mark elements greater than or equal to $x$ with a $1$ on $G_{msk}$, otherwise $0$. $L_{msk}$ is the complement of $G_{msk}$. That means L_msk = ~(G_msk). Start a dfs from every $G_{msk}$ and check if any of it's neighbors is among the $L_{msk}$. If it is, then you found a pair for current $x$ as answer. Notice that it means you found two bitmasks such that bitwise or is `(1<
 » 2 weeks ago, # | ← Rev. 2 →   0 adedalic why didn't you use ceil() function in problem A. I think I got WA on TC 22 because I used ceil(). My solution 1: link My soln 2 :using_binary_search Both give WA in TC 22.
•  » » 2 weeks ago, # ^ |   0 I got AC by using binary search here is the link to my solution:- link
•  » » 2 weeks ago, # ^ |   0 Use double instead of float
 » 2 weeks ago, # | ← Rev. 2 →   0 I am having slow rankups XD.
•  » » 2 weeks ago, # ^ |   +1 I'm much slower than you. But I don't want to give up ever.
 » 2 weeks ago, # |   +14 Very nice solution for problem D (fast and compact one). Also very hard to find out such a nice solution like this. Thank for tough problem and its brilliant solution. This helps me learn more about bitmask which I didnt know too much before. Thanks again!
 » 2 weeks ago, # |   -8 can some one explain editorial of E in simple words ? Thanks ...
 » 2 weeks ago, # |   0 Can someone explain dp approach in problem C
•  » » 13 days ago, # ^ |   +1 Consider the sequence given in the editorial. I'll call it a "good sequence". The answer to the problem is the number of ways of building it. Memoize the amount of good sequences you can build from a position $pos$ given that the last number you used was $last$. These are gonna be the two states.Now, we transition through the states: for every number from $last$ to $n$, try to use it as the $pos$-th element of the good sequence.Submission: 68825881
•  » » » 13 days ago, # ^ | ← Rev. 2 →   0 Would you please tell us(people like me!) how you have created newline in your comment :D
•  » » » » 13 days ago, # ^ |   0 I did (Shift + Enter), but double Enter might do the trick aswell.
•  » » » » » 12 days ago, # ^ |   0 OH!! Thanks a lot ^_^
 » 2 weeks ago, # |   0 not able to implement (n+2*m-1) C (2m)please help me how to do iti tried using tgamma function also astgamma(n)=n-1!
•  » » 2 weeks ago, # ^ |   0 Hope this will be helpful. nCr with MOD
•  » » 12 days ago, # ^ | ← Rev. 3 →   0 you can use nCr = n-1Cr-1 + n-1Cr and use memoization for this problem. you can see my submission for better understanding
 » 2 weeks ago, # |   +20 E can be solved easily using policy based data structure indexed_set and inserting the elements as a pair of negative timestamp of insertion and the index of friend. Every time you remove a friend and insert it at the top, store the max position of current friend, which can be calculated using order_of_key function and adjust the time as -(n+i) where i denotes the ith message, after all the operations loop over all the friends and find the current positions of friends in the set and update max position and min position accordingly.My Solution : 68882102
•  » » 2 weeks ago, # ^ |   0 Although this is a good trick to know, consider using BIT's instead. They're faster. your solution modified: 68888920
 » 13 days ago, # |   0 哈哈
 » 13 days ago, # | ← Rev. 2 →   0
 » 13 days ago, # |   0 May someone please explain B?
•  » » 13 days ago, # ^ |   +4 By the looks, you know it's a math related problem. So get some paper and write down some equation and solve it. So what is the equation? a*b + a + b = conc(a,b). Now the conc() part is mathematically weird. So you change it into real math. conc(12,23) = 1223 = 1200 + 23. So you are just putting 0s at the end of a, how many? equal to the number of digits that b has that is the length of b, then you are just adding b. So conc(a,b) = a*10^len(b) + b. Now by simple math you have b = 10^len(b) — 1. What does that mean? You started from a*b + a + b = conc(a,b). So if that is true then you have b = 10^len(b)-1, that is b must be equal to some power of 10 minus 1. you know that "some power" is the length of b. and (some power of 10) — 1 is always 9,99,999 etc. You can pick b = 9, 99, 999 or any such number. Then for every a, a*b + a + b = conc(a,b) is true. So all we need to find is how many 9, 99, 999 or this type of number there is within the given range of 1 to b, and you know for each of this kind of number , every possible a is a valid answer. For example, for the input 4 11, you know between 1 to 11 only 9 is a valid b. and for that b every a from 1-4 is a valid answer. so your answer is 1*4 = 4.
•  » » » 13 days ago, # ^ |   0 nice explanation sami I just want to add that you can easily calculate the length of the number b by using 10 based logarithm as b will always be 9 or 99 or 999... so you can get |b| using log10(b+1)
 » 13 days ago, # |   0 I haven't understood this part of problem A tutorial -> "Since the ceiling function is monotonically increasing so we can assume that ⌈f(x)⌉≤⌈f(x+1)⌉ for all x>=sqrt(d)"
•  » » 13 days ago, # ^ |   0 You first need to understand concavity. Try my explanation
•  » » 13 days ago, # ^ |   0 f(x) = x + d / (x+1)^2, differentiate to get the rate of change, f'(x) = 1 — d / (x+1)^2 . When the rate of change is positive the function is increasing. Here, when x >= sqrt(d), d / (x+1)^2 is always < 1, thus 1 — d / (x+1)^2 is always positive. So the function increases without ever decreasing (monotonically increasing) and that means for any x >= sqrt(d), f(x) <= f(x+1).
•  » » » 13 days ago, # ^ |   0 f(x) = x+d/(x+1) => f'(x) = 1 — d/(x+1)^2. So as we are considered about positive slope then 1-d/(x+1)^2 >= 0 and form here we should get x >= sqrt(d) -1. so where is this -1 then?
•  » » » » 12 days ago, # ^ |   0 x >= sqrt(d) — 1 is actually the absolute correct equation. But without math, just by looking (which of course saves time) we could say for x >= sqrt(d) function f starts to increase monotonically so if we just run a loop from 0 to sqrt(d) and check for each value if it satisfies the condition is enough. But if your upper bound is sqrt(d)-1 that is correct too.
 » 13 days ago, # |   0 This competition is great!
 » 13 days ago, # | ← Rev. 2 →   +1 why does this 68940816 for prob A fail on test 50! I have used the values of x that would give minimum.
•  » » 13 days ago, # ^ |   0 Use double instead of float.
•  » » » 13 days ago, # ^ |   0 yep...thanks,it worked
 » 13 days ago, # |   +1 can some one explain the first approach in E and what does the following mean in the editorial "You are just required to count the number of distinct values on some segments."
•  » » 12 days ago, # ^ |   +23 Let's say you want to count the maximum place for friend 4. Consider the sequence4 1 3 1 5 4After the first 4, person 4 is in position 1. Then person 1 moves ahead of them, then 3 moves ahead of them. When 1 messages again, he doesn't move ahead of 4, because he's already ahead. Finally, person 5 moves ahead of 4. So because the segment between the 4's contains 3 distinct values moves, person 4 moves down 3 positions. Thus, for each friend, identify the segments between messages, count the number of unique values of a, and take the largest of them.I had a solution that's a good deal simpler than persistent segment trees, by exploiting the offline nature of the queries. First, a sweep gives another array p such that p[i] is the previous time a[i] messaged (so a[p[i]] = a[i], or p[i] = -1). Each query now takes the form of "how many values of i (l <= i < r) satisfy p[i] < y". I sort these queries by y, and also sort the elements of p by y, then do a sweep that updates and queries a Fenwick tree.Incidentally, one doesn't need to treat the initial state separately. Just prepend n, n-1, n-2, ..., 1 to the given sequence: the initial state is consistent with having received that sequence of messages.
•  » » » 9 days ago, # ^ |   0 Thanks bmerry , very nice explanation .
•  » » » 9 days ago, # ^ |   0 can we solve this using only segment tree (Not persistent segment tree) . We can make segment tree of size m and for each number store the position in array of m where it appears . query for each consecutive positions . Like suppose m is 4 1 3 1 5 4 . Make segment tree of this array and suppose for 4 , we can query (1,5) , (5,5) for finding number of distinct integers between them .
•  » » » » 9 days ago, # ^ |   0 See this answer.
 » 13 days ago, # | ← Rev. 2 →   +6 Why does problem A pass if we brute force from 1 to n ...very weak test set https://codeforces.com/contest/1288/submission/68953916 this is my submission that passededit: got it...it was my mistake...such an input is not possible that should give tle
 » 12 days ago, # | ← Rev. 2 →   0 I wrote some brood for A, and found what: Let's have some val = n/2; So lets check if our condition with x = val is true; Is it okey, and if yes, why it works?) https://codeforces.com/contest/1288/submission/68785380
•  » » 12 days ago, # ^ |   0 Sadly I did exactly the same thing at contest time. But not n/2. I did d/2. And got wa :)
•  » » 12 days ago, # ^ |   0 I also just check with val = n/2 or n/2 +1 or n/2 -1... It passed!!! https://codeforces.com/contest/1288/submission/68792002 taking x+ ceil(d/(x+1)) to be x+ d/x we get x + d/x >= n so nx-x^2-d >= 0 and maxima of nx-x^2-d occurs at n/2.So we will check around n/2.
 » 12 days ago, # |   +3 I really liked $C$. I collected the ideas from many folks and wrote an editorial myself for the $C$ here.Here is my code to all the problems that I solved for this contest, if anybody wants to refer.
 » 12 days ago, # | ← Rev. 2 →   0 please explain D in Div 2.
 » 12 days ago, # | ← Rev. 2 →   0 Can someone explain the editorial of prob A? I am not able to understand it
 » 12 days ago, # | ← Rev. 2 →   0 In problem B understood why b will be of kind 999999...... but how is final answer a*(len(b+1)-1) Can someone explain
 » 12 days ago, # |   0 How can we count the number of distinct values on some segments using segment tree with vectors in node? (In editorial of problem E, "The constraints allow you to do whatever you want: segtree with vectors in nodes, Mo, persistent segtree (I hope ML is not too tight for that)." ) Can someone explain the segment-tree approach?
•  » » 11 days ago, # ^ | ← Rev. 2 →   +3 I think people typically refer to it as a merge sort tree (should be googlable). It's usually used to answer the queries of kind: given $L, R$ and $X$, find the number of values less than $X$ on a range $[L; R]$ of an array.So let's rephrase our subtask to these terms. Build an array $prev$ such that $prev_i$ is the index of the previous occurrence of the value $a_i$ or $-1$ if there is none. Now $query(L, R, L)$ on an array $prev$ will count only the values which have their previous occurrence to the left of the query segment. So for each unique value only its first occurrence in the segment will be counted. Thus the result of the query is the number of distinct values on a segment.My second solution is the example of the implementation.
•  » » » 11 days ago, # ^ |   0 I see, thank you very much! It seems that we can apply this way to online queries.
•  » » » » 8 days ago, # ^ |   0 Can you please explain how to do the task if we have online queries ?
•  » » » » » 8 days ago, # ^ |   +3 I think we can deal with online queries using the same approach pikmike referred, because in this approach we don't need to sort given queries.
•  » » » » » » 8 days ago, # ^ |   0 How can we handle updates too ?
•  » » » » » » » 8 days ago, # ^ |   0 Do you mean updates of values in an array? I refer to only an array whose values are fixed. (Online query means we cannot get next queries before we answer a current query.)
•  » » » » » » » » 8 days ago, # ^ |   0 Yes I mean if I update values in an array too. I got your explanation about online queries.
 » 11 days ago, # |   0 Anyone use BIT for counting number of different number in a given segment for dealing with E :)))?
 » 11 days ago, # | ← Rev. 2 →   0 Any approach for solving D other than bitmask?
 » 9 days ago, # | ← Rev. 3 →   0 You can also solve E in $O((n+m)+m\cdot logn)$ by using an ordered set. SpoilerYou first initialize min and max values of a number to the position where they originally are, and keep a list of keys of the elements. When placing an element to the top, you look at its order in the set and take the maximum of that and its max value now. You change its min value to 1, and its key to something, that is smaller, than all other keys. You also check the maximum of max values and order of elements at the end of the procedure.
•  » » 9 days ago, # ^ | ← Rev. 2 →   0 ordered set is $O(\log n)$ per query. That's literally my third solution but slowed down by using ordered set instead of BIT.
•  » » » 9 days ago, # ^ |   0 I might be wrong but I would say that ordered set is easier, because you don't have to get the idea of reversing the order of people.
 » 9 days ago, # | ← Rev. 2 →   0 Hi, I had a fairly basic(and probably a stupid doubt). But I tried to run a Brute Force for Problem D in the contest and it gave me a TLE. However, as per my calculation, the complexity of my algorithm is O(m*m*n). Since m<=8 and n<=3*10^5, it shouldn't do that(as in throw a TLE). Can somebody explain what am I calculating incorrectly? Here's the submission link: https://codeforces.com/contest/1288/submission/68810165
•  » » 8 days ago, # ^ | ← Rev. 5 →   0 In your program, you switched up the variables; m is what n is in the problem statement and n is what m is. So m is max $3\cdot 10^5$ and n is max 8. This means, that your $O(m^2)$ solution gets TLE. Also, it's not wise to declare arrays with variable sizes, it can cause errors depending on which C++ version and compiler you are using. You can look the details up online. I would recommend using vectors.
•  » » » 2 days ago, # ^ |   0 Oh alright!It took me a while to get it. Thanks! Thank you for the suggestion for using vectors too! I usually do use them however, I get a little uncomfortable sometimes when declaring vectors of multiple dimensions. Thanks a lot for the suggestion. I'll practice more and get used to them.
 » 7 days ago, # |   0 "If we want to verify that the answer is not less than x, we have to choose two arrays such that bitwise OR of their masks is (2^m)−1". Can someone please explain this line to me given in editorial of problem D.
•  » » 2 days ago, # ^ |   0 What we are doing is replacing every value in every array with 1 if it is at least x, and 0 otherwise. For example, if we had arrays {1,2,3,4,5} and {6,5,4,3,2}, and x=4 then these would become {0,0,0,1,1} and {1,1,1,0,0}. These are our "bitmasks." If we OR every pair of values at the same index for these two arrays, we get {1,1,1,1,1}. Interpreting this as a string of a binary number is where we get that this is one less than a power of two, in this case 2^5-1.
 » 7 days ago, # |   0 Guys in https://codeforces.com/problemset/problem/1288/B this problem can (8,9) or (7,9) be answers. 8 * 9 + 8 + 9 = 89 7 * 9 + 7 + 9 = 79 5 * 9 + 5 + 9 = 59 ???
•  » » 2 days ago, # ^ |   0 It is asking how many solutions there are, it is not asking for you to provide a solution.
•  » » » 4 hours ago, # ^ |   0 I'm not providing answers. I'm asking what if this happens. In the future just think before saying something.
 » 2 days ago, # | ← Rev. 2 →   0 I think I'm correctly implementing a Merge Sort Tree for E, giving me O((m+n)log(m+n)) complexity. Can anyone who understands Java help me understand why I'm getting TLE? Thanks!!https://codeforces.com/contest/1288/submission/69596326
•  » » 41 hour(s) ago, # ^ |   0 Never mind; not sure how to delete a message but got it up and running
 » 2 days ago, # |   0 D is a really beautiful question.