Автор awoo, история, 7 лет назад, По-русски

Привет, Codeforces!

В 05.06.2019 17:35 (Московское время) состоится Educational Codeforces Round 66 (рейтинговый для Див. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Роман Roms Глазов, Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

UPD:

Так же от наших друзей и партнёров из Harbour.Space есть сообщение для вас:

Codeforces! Каков следующий шаг на пути вашего самосовершенствования?

Мы понимаем что такое заниматься своим развитием самим — в конце концов, мы стартап-университет, и наш студенческий коллектив является исключительным отчасти потому, что он состоит из людей, которые не ждали, пока кто-нибудь покажет им путь.

Если вы такие же, ваше место в Harbour.Space. Цель нашего университета — создать глобальное сообщество людей такого типа, независимо от возраста и национальности, потому что когда вы работаете самостоятельно, вы можете измениться к лучшему, но когда вы работаете вместе с другими, вы можете изменить Мир.

Если вы считаете, что в вас есть это, то вы нужны нам!

Учебный план является частью того, что делает модули такими особенными. А другая часть? Наши выдающиеся учителя, которые являются лидерами в своих отраслях.

Мы верим в ваши достоинства и потенциал! Станьте частью нашей команды!

Подать заявку→

Поздравляем победителей:

Место Участник Задач решено Штраф
1 mango_lassi 6 145
2 E869120 6 148
3 kiyotaka 6 154
4 244mhq 6 154
5 mzen 6 157

Поздравляем лучших взломщиков:

Место Участник Число взломов
1 Radewoosh 97:-19
2 test_hack 56:-37
3 alvinvaja 30:-10
4 AryaKnight 48:-48
5 nikolapesic2802 30:-14
Было сделано 779 успешных и 1077 неудачных взломов.

И, наконец, поздравляем людей, отправивших первое полное решение по задаче:

Задача Участник Штраф
A okwedook 0:01
B mango_lassi 0:05
C nuip 0:07
D Yushen 0:04
E Sehnsucht 0:20
F ---------- 0:05
G LgndryGrandmasturbator 0:47

UPD: Разбор опубликован

  • Проголосовать: нравится
  • +181
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -6 Проголосовать: не нравится

[deleted]

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Thanks for the consecutive contests! Wish that the problem statements will be neat and clean and short as the previous one. Eid Mubarak everyone!

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +515 Проголосовать: не нравится

»
7 лет назад, скрыть # |
 
Проголосовать: нравится -42 Проголосовать: не нравится

Comment "Is it Rated?" if you want to gain contribution points! (In the negative direction)

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +32 Проголосовать: не нравится

thank u, pik misha!!!!!!!!!!!!!!!!! i love you

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

I never really understood the concept of Educational Rounds. Don't we learn something new from every contest? Why exactly term it Educational?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

awoo is a boy or a girl?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

yes
Konstantin Mertsalov is a nice man , we discussed some math problems with him through skype

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +43 Проголосовать: не нравится

Eid Mubarak to all Programmer.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +172 Проголосовать: не нравится

»
7 лет назад, скрыть # |
 
Проголосовать: нравится -70 Проголосовать: не нравится

First question has wrong limits on K!! Because of this I lost valuable time

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -21 Проголосовать: не нравится

Thanks for the round.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится -28 Проголосовать: не нравится

The worst B problem I have ever solved

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

I really liked D there's a relation between each possibility but I don't know how this is going to help :/ how did you solve it

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

Задача F баян — была на отборе на БГУИР в марте

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem B!! :'( made it the worst contest I gave on codeforces :/ and why cant we use python3 signal in codes :'/

»
7 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +19 Проголосовать: не нравится

I'm so sorry of that. I just wanted to laugh and maybe some upvotes. I didn't think reminding some old joke would be that annoying. Maybe this cause more downvote, but I want to talk some more words. I'm just a kid, please just don't make me cry. :( Last day I started commenting and I got contribution +3. But now it is going down to -4. I'm so depressed by now. I promise I won't write something idiot more. I'm sorry again. Can you help me get my contribution up to 0 again?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

How to solve E?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

can't we solve C using the ternary search?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve problem C?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

What is the proof of correctness of C?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

when will tutorial soln for educational contest will come

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve D?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve G?

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 5  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Let's invent dp0[i][j] and dp1[i][j].
    dp0[i][j] is answer for prefix of length i if we divide into j subsegments
    dp1[i][j] is answer for prefix of length i if we divide into j subsegments such as maximum on the last segment (ending at j) is a[i].
    First, let's learn how to calculate dp1[i][j].
    We find such minimal l that maximum on segment [l; i] is a[i]. Then dp1[i][j] = max(dp1[k-1][j-1] + a[i] * (i — k + 1)) for k in [l; i]. We can notice that we are able to recalc it in O(log n) time using sparse table and Li-Chao tree.
    How to recalc dp0[i][j]. Let's notice that if we recalc it as max(dp1[k-1][j] + a[k] * (i — k + 1)) for k in [j; i] we will get right answer (we can't make it better than it is, because the if we fix left bound, bigger right bound means not lower maximum value). Notice that it can be recalced using Li-Chao tree in O(log n). Total complexity is O(nk log n)

    • »
      »
      »
      7 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      There is something suspicious in your solution:

      1. the problem asks you to minimize, not maximize answer;

      2. it seems like dp1[i][j] = max(dp0[k-1][j-1] + a[i] * (i — k + 1));

      3. and dp0[i][j] = max(dp1[k][j] + a[k] * (i — k)). And it doesn't work if we change max to min, because here it's can be profittable to cut some a[x] > a[k] where k < x <= i.

      P.S.: You wrote your comment "in Russian", so it doesn't show up on the English version of the page.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve G?

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    D̶&̶C̶ ̶D̶P̶ ̶o̶p̶t̶i̶m̶i̶z̶a̶t̶i̶o̶n̶ I'm actually not sure(there is no editorial for task, so I wrote what i remembered it was), thx for pointing it out

    By the way, the problem is not original, statement is only in romanian though

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +35 Проголосовать: не нравится

    I have an $$$O(NKlog)$$$ solution for G but still havent been able to implement it until now which ruins my rating as always :)

    So we lets denote $$$MAX(L, R)$$$ be the maximum value in the subarray $$$[L, R]$$$, and $$$F(i, j)$$$ as the minimum weight of splitting first $$$i$$$ elements to $$$k$$$ subsegments.

    By that, we have $$$F(i, j) = min(F(x, j - 1) + MAX(x, i) * (x - i + 1)))$$$ for every $$$x ≤ i$$$.

    Lets have an observation:

    We can separate $$$(i - x + 1) * MAX(x, i)$$$ to $$$(i - 1) * MAX(x, i) - x * MAX(x, i)$$$. As always, we will have some data structre like Convex Hull or Lichao Tree to query for the minimum $$$w* MAX(x, i) - x * MAX(x, i) + F(x, j - 1)$$$ for $$$w = i - 1$$$.

    Now, normally, one will always think of idea of iterating elements from left to right, maintaining the stack of maximum elements and trying to do something about deleting and pushing elements to that stack. As every time $$$MAX(x, i)$$$ changes, we will need to reset our Convex Hull or Lichao Tree over again.

    Lets fix $$$i$$$. Now our stack will represent the changes of the $$$MAX(x, i)$$$ if we iterates $$$x$$$ from $$$i$$$ to the left. And for every fixed $$$k$$$, the elements that satisfy $$$MAX(x, i) = k$$$ lies on a continuous subarray. So my main idea is for each $$$k$$$, i will first find the $$$x$$$ that minimizes $$$-x * k + F(x, j - 1)$$$ before we actually inserting it to our Lichao/Convex Hull.

    To do this, you can think of an segment tree which each of its node has a Convex Hull or Lichao tree to take this query. And we will use Convex Hull in this case. If we notice that every time we try to change the $$$MAX$$$ of some subarray by deleting some elements from our stack, their $$$MAX$$$ only gets bigger and bigger. So if we use Convex Hull, we can actually handle queries in $$$O(1)$$$ by using the pointer trick instead of binary searching.

    Now once we get the best $$$x$$$ for our $$$k$$$, we will insert a line $$$(k, -x * k + F(x, j - 1))$$$ to our Lichao Tree and take queries later.

    But another thing to notice is that if some elements are poped out from our stack, the Lichao tree should also be changed. But luckily, only the top elements are deleted from our stack so its prefix is still the same. Here, we can use a persistent Lichao Tree to handle this case.

    So my time complexity is actually $$$O(NKlogC)$$$ for building the segment tree of ConvexHull and $$$O(Nlog)$$$ memory for having a persistent Lichao Tree.

    Since this solution is pretty much disgusting, I hope its not author's solution. But i dont want his solution to be $$$O(Nkloglog)$$$ either cause I didn't expect it to pass and spent all my contest thinking of a better (not the one above lol) one.

    • »
      »
      »
      7 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +15 Проголосовать: не нравится

      "...I hope it's not the author's solution..." - Your hope is futile.

      On the other hand, I was sure, that there would be much better solutions.

      • »
        »
        »
        »
        7 лет назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится +29 Проголосовать: не нравится

        Here's a similar solution but maybe easier to implement.

        Denote $$$D_{i, j}$$$ as the minimum cost to split prefix $$$i$$$ to $$$j$$$ subarrays. we fix $$$j$$$ and solve the layer in $$$\mathcal{O}(n \log n)$$$.

        We compute the answer for all $$$i$$$ in a D&C fashion; to compute the answer for all $$$l \le i \le r$$$, first recursively solve for $$$[i, m], [m + 1, r]$$$ where $$$m = \frac{l + r}{2}$$$, and then we consider transitions between the two halves.

        define $$$A_i = \max(a[m+1...i]), B_i = \max(a[i...m])$$$, the transition is

        $$$D_{i, j} = \min_{k \le m} (D_{k, j-1} + (i - k) * \max(B_k, A_i))$$$

        Notice that due to monotonicity of $$$A, B$$$, for fixed $$$i$$$ there is a suffix of the first half where $$$A_i$$$ is larger, and a prefix where $$$B_j$$$ is larger. We can solve both cases independently;

        $$$D_{i, j} = \min_{k \le m} (D_{k, j-1} + (i - k) * A_i) = \min_{k \le m} (D_{k, j-1} - k * A_i) + i * A_i$$$

        We have a linear function inside (for constant $$$k$$$), so we can maintain those in a cht. When we increase $$$i$$$, the suffix in which $$$A_i$$$ dominates increases, and we repeatedly add functions with smaller slopes, so we can do this in $$$\mathcal{O}(n)$$$.

        The case when $$$B_k$$$ dominates is almost identical, same analysis.

      • »
        »
        »
        »
        7 лет назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится +14 Проголосовать: не нравится

        Here's another boring solution.

        As many said, DP formula should be like $$$dp(i, R) = \min(dp(i - 1, L - 1) + (R - L + 1) \cdot \max(a_{L}, a_{L + 1}, \ldots, a_{R}))$$$ $$$(L \leq R)$$$.

        Now let's rewrite this formula using $$$a_{M}$$$ $$$(L \leq M \leq R)$$$ as any maximum element in that subarray, and then we can boost the transmitting process of $$$L \to M$$$ and $$$M \to R$$$ separately.

        Denote $$$[left(M), right(M)]$$$ as the maximal subarray that contains $$$a_{M}$$$ as its maximum element. For each $$$M$$$, we first calculate $$$f(M) = \min(-(L - 1) \cdot \color{red}{a_M} + dp(i - 1, L - 1))$$$ $$$(left(M) \leq L \leq M)$$$, and then we update $$$dp(i, R)$$$ $$$(M \leq R \leq right(M))$$$ by $$$(a_M \cdot \color{red}{R} + f(M))$$$.

        In both parts, we only need to answer the minimum inner product for a query 2D vector (e.g. $$$(a_M, 1)$$$ or $$$(R, 1)$$$) with one vector (e.g. $$$(-L + 1, dp(i - 1, L - 1))$$$ or $$$(a_M, f(M))$$$) selected from a certain set.

        To implement easily, we can maintain two segment trees of convex hulls offline. Since we don't need to support insertion and query for segments simultaneously, and we can sort the points in increasing order of the first coordinate, we can solve the problem in $$$\mathcal{O}(n k \log n)$$$.

        • »
          »
          »
          »
          »
          7 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          I don't know how to work without supporting insertion and query for segment simultaneously. For answering $$$f(M)$$$ , we need to know the minimum inner product, it can be solved by working binary search on segment tree with $$$O(log^2n)$$$. And for updating $$$dp(i,R)$$$ , we need to maintain a set by stack and use Li Chao tree with the same complexity. I can't understand how to solve this problem by sorting the point:(

          • »
            »
            »
            »
            »
            »
            7 лет назад, скрыть # ^ |
            Rev. 2  
            Проголосовать: нравится +8 Проголосовать: не нравится

            Let's maintain two SegmentTrees, in which each node stores the convex hull of a set of points. By doing insertions and queries offline, we can insert points in increasing order of the first coordinate (which means you only need to append points at the end of each hull) and then resolve query points in increasing order of the first coordinate, which means you only need to calculate the inner product between each query point and the point at the end of each hull (and drop useless points when it's necessary). Note that we avoid any binary search by doing things offline.

            The outline is like this:

            • insert all points obtained from $$$dp(i - 1, \ldots)$$$;
            • query all points needed to calculate $$$f(\ldots)$$$;
            • insert all points obtained from $$$f(\ldots)$$$;
            • query all points needed to calculate $$$dp(i, \ldots)$$$.

            Here is my submission: 55180395

  • »
    »
    7 лет назад, скрыть # ^ |
     
    Проголосовать: нравится -19 Проголосовать: не нравится

    It can be solved with ordinary segment tree. With time complexity O(NKlogN). Our dp will dp[k][n], where k is number of groups, and n is representing last added to some group. Now let's focus on solving only one dp layer in terms of group. Update segment tree by setting cost of each index to value of dp[prevgroup][that_index]. Now iterate from left to right, suppose that we are at index i now. Each index will have some cost in segment tree. Now our reccurence will be dp[i] = min dp[j] + cost(j,i). This can be easily found if we can calculate efficiently cost(j,i). Instead of calculating it each time, we will somehow update it efficiently. We can do so by grouping elements by maximum element from them to our i. Now one can see that when moving right, we can find where this element represents maximum. And set it as maximum for new group, while deleting previous groups that those elements belong to. Only thing that is left is that maximum is multiplied by length. We can handle this again by segment tree arithmetic progression update (it can be found easily on net, i am lazy to write about it now). I hope i helped.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

why ternary search is not correct for problem C? i am getting WA on test case 2.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why my this solution for B is failing on test 8 . Solution

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

What is the hacking penalty and profit for Educational round?

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -8 Проголосовать: не нравится

Задача G была на Республиканском олимпиаде Казахстана (ROI) 2018 года), Задача F

»
7 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

G была на Республиканской олимпиаде Казахстана problem F

Solution by Tima

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

Can anyone help what's wrong in this submission for Problem B. 55174319 Thank you!

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +50 Проголосовать: не нравится
»
7 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

What is hacking test case for B)?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

Why there are so many hacks in B? Weak Test Cases?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

I saw some of the solutions for F rely on the fact that the answer will not be too large. Does anyone want to give a proof/intuition on that?

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +54 Проголосовать: не нравится

    Let a valid subarray be $$$a_{l}, a_{l + 1}, \ldots, a_{r}$$$.

    Observation 1: Pick up all the elements of value $$$1$$$. For every two adjacent elements $$$1$$$, denoted by $$$a_{x}$$$ and $$$a_{y}$$$, if $$$l \leq x$$$, then it must be held that $$$x \leq r \lt y$$$.

    More generally, for every three adjacent elements $$$1$$$, denoted by $$$a_{x}$$$, $$$a_{y}$$$ and $$$a_{z}$$$, $$$x \lt l \leq y$$$ must lead to $$$y \leq r \lt z$$$.

    Observation 2: Let's fix the position of value $$$1$$$ as $$$a_{k}$$$ ($$$l \leq k \leq r$$$). Without loss of generality, we assume the position of value $$$(r - l + 1)$$$ is on the right of $$$a_{k}$$$, and then we can conclude the only one possible $$$l$$$ by enumerating $$$r$$$, as we know $$$l = r + 1 - \max(a_{k}, a_{k + 1}, \ldots, a_{r})$$$.

    Consequently, there are at most $$$2 n$$$ possible subarrays that we need to check if the elements in each subarray are distinct.

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +30 Проголосовать: не нравится

Why this solution of D is wrong? Take the cut $$$[ k, n ]$$$ and find maximum suffix of it, $$$[ l, n ]$$$. Increase answer by the sum on $$$[ l, n ] * k$$$. Then find the maximum suffix of $$$[ k-1, l-1 ]$$$ and so on. In the end, if there some elements in the beggining of the array, which weren't counted in any suffix, also add them to answer. We can do all this with the segment tree in $$$O ( ( n + k ) \log n )$$$.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can you tell me why it gives WA in test 9? https://mirror.codeforces.com/contest/1175/submission/55166598

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Was I the only person who felt B was trouble-some and spent more time on it compared to C and D?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone tell me why I will get WA in T5? Thansk. 55187500

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

At first, there was a legend related to the name of the problem, but now it's just a formal statement.

Does someone know about that legend?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

editorial?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem B it was specified "x is an integer variable and can be assigned values from 0 to 2^32−1" so doesn't it means the range of x is [0,2^32-1] and the number 2^32-1 should be included or my English is just bad?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My Submission got accepted during the contest 55132811 but after the contest ended the status changed to Compilation error. I checked the same code on custom invocation and it compiled without any errors. What the heck is going on!! Can somebody explain?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Ok, feels lucky for being expert again :^)

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello everyone! Answer me please. Why is my solution for C getting TL? What's wrong? https://mirror.codeforces.com/contest/1175/submission/55161342 Please, help)

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Help!! Could someone please explain how to solve C what does ar[i+k]-ar[i] even mean;

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Господа, хотелось бы увидеть разбор, хотя бы краткий, по решениям не всё очевидно. Заранее спасибо.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Any hint for F?

  • »
    »
    7 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +13 Проголосовать: не нравится

    (l,r) is a subpermutation iff r = max(l,r) + (l-1) and all values in(l,r) are unique. so we try to find out how many valid l are there for a fixed r, and this can be done by a segment tree with lazy propagation

    • »
      »
      »
      7 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      Can it be solved via BFS? Start bfs at each 1 with state (i,i+1), from (l,r) next state is (l-1,r) if a[l-1] == r-l+1 and (l,r+1) if a[r+1] == r-l+1. Increase answer by 1 for each state reached. Bound is number of permutations, which should be much less than N^2.

    • »
      »
      »
      7 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Can you explain how to find number of valid l for a fixed r using segment tree with lazy propagation

      • »
        »
        »
        »
        7 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +3 Проголосовать: не нравится

        If all values are unique in range (l,r) then r <= (l-1) + max(l,r). Its equal only when (l,r) is a subpermutation. So for a fixed index r, in each l such that l<=r we need to have (l-1)+ max(l,r), and in each node of segment tree we need to store the minimum in that and a count denoting in how many indices that minimum occurs. As you go right and your r changes, the max (l,r) for some l is changing. You can maintain the maximum with the stack technique. And in segment tree you need to handle that with lazy propagation. You can have a look at my code for a better understanding. 55194670

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone help me find the problem with my code for problem B ?

Submission: https://mirror.codeforces.com/contest/1175/submission/55197218

»
7 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain why it is giving wrong answer on test case 8 in problem B? My submission-55198130

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

where is editorial ??

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Why isn't the editorial out yet?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

When will tutorials come ?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится