Блог пользователя vovuh

Автор vovuh, история, 5 лет назад, перевод, По-русски

Внезапно, все задачи, кроме A и D, были придуманы мной. Автор A и D — MikeMirzayanov.

1234A - Очередное приравнивание цен

Разбор
Решение

1234B1 - Социальная сеть (простая версия)

Разбор
Решение

1234B2 - Социальная сеть (сложная версия)

Разбор
Решение

1234C - Трубы

Разбор
Решение

1234D - Запросы на различные символы

Разбор
Решение

1234E - Специальные перестановки

Разбор
Решение

1234F - Очередной разворот подстроки

Разбор
Решение
WA?
Разбор задач Codeforces Round 590 (Div. 3)
  • Проголосовать: нравится
  • +112
  • Проголосовать: не нравится

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

Fenwick appraoch for 1234D : Solution

Implementation similar to: CodeMonk Problem

Awesome contest by the way! :D

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

    I used bitmasks and segment tree instead: 61684182

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

      I also used a segment tree but I used sets instead of bitmasks: 62130226

      Apparently 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?

      • »
        »
        »
        »
        5 лет назад, # ^ |
        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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you please tell me how you came with the intuition of using Fenwick tree?

    • »
      »
      »
      5 лет назад, # ^ |
      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

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +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!

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

        Thanks.. I accidentally down voted instead of up voted. I cannot change it now. I am really sorry.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 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!

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 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.

      • »
        »
        »
        »
        5 лет назад, # ^ |
        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).

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

    Hi Dsxv

    1234D

    I 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

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

    Hey!!
    What how will we solve the problem D if we are asked the count of distinct characters which occur more than two times in range??
    Also can you suggest something where I can read about the BIT topic

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

My solution to E: https://codeforces.com/contest/1234/submission/61676673

Just 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

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

    can you please elaborate?

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 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?

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

Weak Example in F makes me WA on 5........ I want strong example QAQ (sorry to my poor English :D

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

How can we do C with dfs?

»
5 лет назад, # |
  Проголосовать: нравится 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 ?

»
5 лет назад, # |
  Проголосовать: нравится 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 fail

Though If anyone finds the reason behind the behaviour of WA code in Custom Innovation, do let me know. I'm quite curious about this.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +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).

»
5 лет назад, # |
  Проголосовать: нравится 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.

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

I also applied segment tree approach 61686336. But it's giving TLE. Can anyone please tell me where I went wrong?

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

    @gaurav_iiitian check my code I used segment tree and it got accepted. My code was easy to understand..

    link — https://codeforces.com/contest/1234/submission/61689286

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 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.

      • »
        »
        »
        »
        5 лет назад, # ^ |
        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.

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

    I also got TLE when I implement segment Tree with Python...@admin please have a look at this..

»
5 лет назад, # |
  Проголосовать: нравится +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.

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

Why does ceil(double(sum)/n) give a wrong answer on but (sum+n-1)/n doesn't.

»
5 лет назад, # |
  Проголосовать: нравится 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

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

Решение в $$$E$$$ ломается, потому что в пересчёте длин предполагается, что второй элемент будет оставаться на месте, что не верно в случае $$$x_i = x_{i + 1}$$$.

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

    Да, я понимаю, из-за чего это, и где именно ломается формула, но просто решил важным сообщить, что именно это может быть ошибкой.

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

D можно решить с помощью дерева Фенвика/ отрезков + использовать что-то похожее на префиксные суммы. Сделаем несколько наблюдений: 1). Если мы меняем конкретный символ, то значение префиксных сумм(количество элементов на префиксе) на подотрезке с pos до конца строки уменьшится на 1.

2). Для нахождения ответа на 2 запрос следует проверить, что на подотрезке с r по l-1 был хотя бы один символ (то есть значение префикс.сум[r]-префикс.сум[l-1] было больше 0)

3). Чтобы хранить значение префиксных сумм всех 26 букв английского алфавита, будем использовать двухмерный мас сив (при этом не только префиксные суммы, но и дерево отрезков/Фенвика)

4). Обновляли значение конкретных символов на подотрезке — (в Фенвике/ДО добавлял и в случае,если меняли на данный символ, вычитали, когда меняли данный элемент) — префикс.сум[r]-префикс.сум[l-1]+(значение в дереве[r]-значение в дереве[l-1]) (на подотрезке с pos до длины строки вычитали на 1 в случае уничтожения(изменения) данного элемента, прибавляли на 1 в случае изменения на данный элемент)

Теперь осталось реализовать ДО/Фенвик и использовать данные наблюдения.

»
5 лет назад, # |
  Проголосовать: нравится -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

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +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).

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

Damn slow python... Got TL with Segment Tree

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

Very Nice Explanations and Clear Editorials.

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

I wonder why I got TLE in pronlem D when using Segment Tree......(61656622)

(sorry for my poor English x(

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

My solution got tle in D in system testing and the same solution is accepted on submitting after System testing

https://codeforces.com/contest/1234/submission/61710080

https://codeforces.com/contest/1234/submission/61641496

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

I think this is not as simple as before

»
5 лет назад, # |
  Проголосовать: нравится 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:61711501
The map version AC:61711675

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

    You can read this

    If you use unordered_map, your time complexity may up to O(n).

    (and, sorry to my poor English

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

SquareRoot Decomposition approach for D: 61667541

»
5 лет назад, # |
  Проголосовать: нравится 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?

»
5 лет назад, # |
  Проголосовать: нравится 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.

»
5 лет назад, # |
  Проголосовать: нравится 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

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 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

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 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.

»
5 лет назад, # |
  Проголосовать: нравится 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: 61716953

TLE on test 20: 61712878

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 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

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 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.

»
5 лет назад, # |
  Проголосовать: нравится 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.

»
5 лет назад, # |
  Проголосовать: нравится 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)

»
5 лет назад, # |
  Проголосовать: нравится +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 n

Here is the code : https://codeforces.com/contest/1234/submission/61666909

»
5 лет назад, # |
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

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +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.

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

    He has decremented values of a[i] initially that's why res[i]=j+(j<i).

»
5 лет назад, # |
  Проголосовать: нравится +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

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

Can somebody explain me problem F's soln? Sorry but i am unable to understand the editorial?

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

Need DP idea of Problem C.

»
5 лет назад, # |
  Проголосовать: нравится 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?

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +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 011011

    This is my opinion so correct me if I'm wrong <3

    • »
      »
      »
      5 лет назад, # ^ |
      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.

      • »
        »
        »
        »
        5 лет назад, # ^ |
          Проголосовать: нравится +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

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

Didn't understood the tutorial of E could someone pls elaborate on making prefix arrays.

  • »
    »
    5 лет назад, # ^ |
    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<j<r$$$, we want to add $$$r-l-1$$$,
    • for index $$$j = r$$$, we want to add $$$l$$$,
    • for indices $$$j > 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

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

      How did you come up with those five contributions ?

      Edit: Nevermind, that's simple observaton. Got it.

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

Problem A can also be solved using binary search :: Solution : https://codeforces.com/contest/1234/submission/61633785

»
5 лет назад, # |
  Проголосовать: нравится 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.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 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])]$$$

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

Has someone solved D with a segment tree with bitmasks, or am I alone dumb?

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 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)

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

F. Yet Another Substring Reverse ( with explanation )

Check out my solution for more detailed explanation : 61824886

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

Умные люди можете объяснить почему это так: "...нам нет смысла рассматривать такие пары xj и xj+1, что xj=xj+1...". Ответы: "Так написано в разборе" не принимаются)

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

what is __builtin_popcount??? i don't know it

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

F is beautiful problem

»
5 лет назад, # |
  Проголосовать: нравится 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?

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

I guess I find a counter test case you mentioned in Tutorial-1234F.

#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
using namespace std;
const int N = 1e6;
int main()
{
  std::srand(std::time(nullptr));
  int i = 0;
  for(; i < 19; ++i) {
    cout << (char)('a'+(i%19));
  }
  for(; i < N-2; ++i) {
    cout << (char)('a'+(rand()%19));
  }
  cout << "aat" << endl;
}

The answer should be 20, but may got 19 when using WA?-solution. counter test case like this

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

Problem A should had to be explained more clearly and easily with notes

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

Did Problem E, With segment tree lazy propagation Solution 88938957. For detailed explanation comment below.

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

I loved the question D..

»
20 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

D can be solved in a very straightforward way with Segment Tree and bitmasks. Each node should contain a bitmask detailing which letters are present in it's subtree. During calculation, nodes can be combined using bitwise OR, and the final result can be read with __builtin_popcount().

»
15 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

i solved problem F using SOS dp. it is my first problem where i used SOS dp when solveing problem randomly.