380.md (3605B)
1 Source: https://codeforces.com/blog/entry/10363 2 3 ### [381A - Sereja and Dima](/contest/381/problem/A "Codeforces Round 223 (Div. 2)") 4 5 Simply do the process described in the statment. 6 7 ### [381B - Sereja and Stairs](/contest/381/problem/B "Codeforces Round 223 (Div. 2)") 8 9 Calculate the amount of each number. For all the different numbers — maximum possible times of use isn't more than 2 times. For the maximum is is only — 1. 10 11 ### [380A - Sereja and Prefixes](/contest/380/problem/A "Codeforces Round 223 (Div. 1)") 12 13 Generate the first number 100000. Will in turn handle the requests, if the request gets to the point of adding one number, just print it. Otherwise see what element will meet our and just print it from precalculated array. 14 15 ### [380B - Sereja and Tree](/contest/380/problem/B "Codeforces Round 223 (Div. 1)") 16 17 Lets generate a tree as described in the statment. For each request to add items we just add a segment for a certain level. At the request of the number of items we just go through all the lower levels, considering the leftmost and the rightmost vertex in the subtree. To each level will take all intervals that it owns and for each check — whether it intersects with the interval that we have generated in the current stage. If so, simply add items to the set. The complexity of solving *O*(*n*·*m*). 18 19 ### [380C - Sereja and Brackets](/contest/380/problem/C "Codeforces Round 223 (Div. 1)") 20 21 We will support the segments tree. At each vertex will be stored: 22 *a**v* — the maximum length of the bracket subsequence 23 *b**v* — how many there it open brackets that sequence doesn't contain 24 *c**v* — how many there it closed brackets that sequence doesn't contain 25 If we want to combine two vertices with parameters (*a*1, *b*1, *c*1) and (*a*2, *b*2, *c*2), we can use the following rules: 26 *t* = *min*(*b*1, *c*2) 27 *a* = *a*1 + *a*2 + *t* 28 *b* = *b*1 + *b*2 - *t* 29 *c* = *c*1 + *c*2 - *t* 30 31 ### [380D - Sereja and Cinema](/contest/380/problem/D "Codeforces Round 223 (Div. 1)") 32 33 In order that no one would be upset, every person except first should sitdown near someone else. Now when any human comes we know that for one side of him there will not be any people. Will use it. We will support the interval exactly occupied seats. If the first person is not known, it is possible that we have 2 such intervals. Now only remains to consider carefully all the cases that could be, because at each iteration we know exactly how many people will sit on some certain place. 34 35 ### [380E - Sereja and Dividing](/contest/380/problem/E "Codeforces Round 223 (Div. 1)") 36 37 Note that at any particular segment we are interested not more than 60 numbers. The greatest number enters with a coefficient of 1/2, the following — 1 /4, 1 /8, and so on. Thus to solve the problem we need to know for each number: how many segments to include it as a maximum , as a second maximum , a third , and so on until the 60th . 38 39 What to know such information is sufficient to find 60 numbers large jobs left and right. This can be done carefully written the set or dsu. 40 41 Now, with this information we can calculate by countind number of segments which contain our element. It is not difficult to do, knowing the positions of elements , large then current . Let the position of elements on the left: *p*1> *p*2> ... > *P**s*1. And positions right: *q*1 < *q*2 < ... < *q**s*2. So we should add value . 42 43 All details can be viewed in any accepted solution.