Автор awoo, история, 4 месяца назад, По-русски

Привет, Codeforces!

В 18.01.2024 17:35 (Московское время) состоится Educational Codeforces Round 161 (Rated for Div. 2).

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

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

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

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

Спасибо тестерам раунда shnirelman и Minder за ценные советы и предложения!

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

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

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

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

Hopefully I reached Expert :)

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

I wish everyone a good contest!

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

Good luck to every Contestant!

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

My 3rd rated contest. Wonder if I could reach True Rating 1700(displayed 1400)

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

Good Luck and Have Fun everyone!

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

Good luck to everyone

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

Hope this round aint Mathforces af. Usually, Edu rounds = Mathforces

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

What's the difference between an educational round and normal div 2 round?

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

Such a short and clear announcement I hope problems statements be like this too!!!

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

Hopefully I can get Pupil(not Newbie) :/

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

BledDest Round

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

Lets, Hope I can get Expert color.

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

Hope I can get Expert badge.

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

Hopefully I reached Specialist :)

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

Hope for a positive delta.

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

How many problems I need to solve to become a Pupil in this contest?

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

Educational round is overrated

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

Educational round means you have to study gcd well :)

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

l have nothing big,Pupil hop to be reached!

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

Hope i reach specialist

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

I hope to bring the pupil back again. Good luck for everyone!

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

As I screwed up in the last div3, I hope to solve 3-4 problems in this round :|

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

anxiety

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

bad explanation of first question

»
4 месяца назад, # |
Rev. 3   Проголосовать: нравится -59 Проголосовать: не нравится

[deleted]

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

This First question made me skip contest man :(

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

Didn't realize E was easier ,should've tried that first.

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

B was a good problem for such a simple concept but i made 2 wrong submissions.

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

    Yes! Problem statements were clear and precise. But I must be blind... :(

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

I have skill issue

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

Was C that easy ? is it based on some standard algorithm/ some standard problem ? i was thinking in direction of Floyd Warshall algorithm. but could not come up with solution. I'm seeing around 7000 successful submissions. or it was based on something else like Dijkstra/DFS/BFS ??

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

    i pre-calculate cost of go forward and backward

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

    This problem maybe doesn't require the shortest path algorithm

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

    C was a modified version of prefix sums

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

    It can be shown that in order to go from point x to a point y, going back is never a good choice.

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

Damn, the first question reduced my life by a few years. :')

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

I have skill issue

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

I think E was way easier than it ought to be. Good contest nevertheless.

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

Wasted too much time in problem A :/

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

can someone please explain problem A? Thanks in advance.

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

    this took me 90 minuts to figure out

    loop from 1 to n if(a[i]==b[i]&&c[i]!=a[i]) then yes and break if(c[i]!=a[i] && c[i]!=b[i]) yes and break

    print no if loop finished without any yes

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

      but the question said if there is one wrong letter then its a NO??

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

      Same lol!. Usually the first problem is too stressful than other problems

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

      only condition 2 is enough

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

      if a="ab", b="cd", c="ef" then what will be the template string t? suppose t= "EF", but it matches with string c also, right? Sorry if my question sounds dumb.

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

        In order to print "yes," it should not match the condition with the third string. So, "EF" matches with the first and second strings, because none of them is equal to "ef,",the third string should not match the condition. This is what is happening in our case because "EF" means that the string should be different from "ef," but it is "ef," so it doesn't match the required condition. Therefore, we print "yes."

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

    Count the number of positions with a!=b but( b==c or a==c) and also if all are equal then if the count is ==n it's no otherwise it's yes

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

awoo Loved the D and people think LinkedList is overrated.

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

    I actually used TreeSets/Ordered Set to track the previous and next poitners. Unfortunately was not able to solve. If someone could help me identify my mistake in the solve function (Java Code):

        static void solve(IO io) throws IOException {
            int[] params = io.readIntArray();
            int n = params[0];
            // int k = params[1];
            long[] attack = io.readLongArray();
            long[] defence = io.readLongArray();
            TreeSet<Integer> alive = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                alive.add(i);
            }
            HashSet<Integer> active = new HashSet<>();
            active.addAll(alive);
            for (int i = 0; i < n; i++) {
                HashSet<Integer> dead = new HashSet<>();
                HashMap<Integer, Long> damage = new HashMap<>();
                for (Integer j : active) {
                    Integer prev = alive.lower(j);
                    Integer next = alive.higher(j);
                    if(prev == null && next == null)
                        continue;
                    else if(prev == null){
                        damage.put(next, damage.getOrDefault(next, 0l) + attack[j]);
                    } 
                    else if(next == null){
                        damage.put(prev, damage.getOrDefault(prev, 0l) + attack[j]);
                    }
                    else{
                        if(j - prev == next - j){
                            damage.put(next, damage.getOrDefault(next, 0l) + attack[j]);
                            damage.put(prev, damage.getOrDefault(prev, 0l) + attack[j]);
                        }
                        else if(j - prev > next - j){
                            damage.put(next, damage.getOrDefault(next, 0l) + attack[j]);
                        }
                        else 
                            damage.put(prev, damage.getOrDefault(prev, 0l) + attack[j]);
                    }
                }
                for (Integer j : damage.keySet()) {
                    if(damage.get(j) > defence[j]){
                        dead.add(j);
                    }
                }
                for(Integer j: dead){
                    alive.remove(j);
                }
                active.clear();
                for (Integer j : dead) {
                    if(alive.lower(j) != null){
                        active.add(alive.lower(j));
                    }
                    if(alive.higher(j) != null){
                        active.add(alive.higher(j));
                    }
                }
                io.append(dead.size());
            }
            io.newLine();
        }
    
  • »
    »
    4 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    bro u fell of

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

    Still do think its overrated after writing this piece of art which even i can't read now Submission

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

    Bro just use set

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

I hate segment trees

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

wtf is B ? , is it same like https://codeforces.com/problemset/problem/1119/E ??

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

I got drown in caseworking C. Any ideas on avoiding, like, a dozen of caseworks?

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

    you can create a Generic function that decrease the number of those caseworking.

    242254308

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

      Wow! That was neat!

      I tried to partition the array into several groups, and each group contains two "center" cities where everyone leads to, and then hop between the groups before caseworking the best answer out when they are in the same group.

      That was painful. Those with a daring soul may see it here --> 242305848

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

Stucked in Question B till last not able to optimise.

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

my first E yaaaaaaaaaaay

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

Anyone feel like the wording on A was weird?

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

    Took me 20 minutes and out of the contest to understand the concept of "uppercase is lowercase this time".

    I do not understand how problemsetters cannot see that such a wording is bad.

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

what is the approach for B?

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

    Note that the sides of the triangles are powers of two. So, at least two of the sides have to be equal. This observation makes it a lot easier.

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

      how to count the valid triplets?

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

        Use combinatorics, create a map to keep track of frequency, for each frequency in map, you can choose 3 sides of same length NC3 (N = frequency of element and you can choose 2 same sides and 1 from smaller sides, NC2 * CF (cumulative frequency before the current element). Intuition is 2^k + 2^(k + 1) is less than 2^(k + 2) using GP formula you can prove, therefore 3 sides cannot be unique, isosceles and equilateral triangles can be formed

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

E was basically APIO 2022 P3 with nerfed limits?

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

How to solve F?

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

Good contest

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

I submitted B 14 times ;-;

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

Did the authors intend to cut off solutions to D that uses two std::sets? I got TLE on my first attempt before finally switching to segment trees.

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

    No, I used two std::sets as well and it passed in 700ms

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

      same, my passed in 389ms

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

      Same. It was meant for Set. At any point if you remove X elements, you will iterate for 2*X elements and out of which if you remove Y elements, next time you will iterate for 2Y elements. So overall 3*N operations will be carried out.

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

      I see. I guess it was my implementation that was inefficient, then.

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

    How did you solve it by segment trees? Like what was each Node storing, can you please share.

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

      The segment tree was only used to get the global minimum of the remaining health points of each monster (i.e. $$$d_i$$$ minus the total attacks dealt to it). Each node stored the minimum of that value among all indices in its range, as well as the index that caused that minimum value. This allows us to simulate each round and find out which monster died during the round.

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

    I used linked list — 265 ms.

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

    I used 2 vectors and a static linked list. It's supposed to be O(n)...

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

C was intuitively not too hard.. just too painful to implement.

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

How to guess the solution of problem E?

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

    Notice that this problem appeared in APIO and copy paste

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

    maybe 10^18 gave me a hint towards set bits....

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

    10^18 says it should be done in O(logn).

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

      I'm pretty sure it can be done in O(n), using the fact that increasing array of length n contains exactly 2^n increasing subsequences. Oh, I meant n being the length of resulting array.

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

    I think considering case of $$$1, 2, 3, 4, 5, 6 ...$$$ is very natural.

    Then understanding $$$1, 2, 3, ... , n$$$ gives $$$2^n$$$, should be enough to be able to construct solution

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

      I tried this idea. I noticed, that if I have blocks, which look like: $$$|10 \; 11 \; 12|7 \; 8 \; 9|3 \; 4 \; 5 \; 6|1 \; 2|$$$, and their lengths are $$$a_1, a_2, \dots, a_k$$$, then number of subsequences is $$$(2^{a_1} - 1) + \dots + (2^{a_k} - 1) + 1$$$. Then I can factorize $$$x$$$ in sum of degrees of $$$2$$$. For example, $$$37 = 2^0 + 2^2 + 2^5 = (2^5 - 1) + (2^2 - 1) + 3$$$, so I use $$$a = {5, 2}$$$ and append two decreasing numbers at the end.

      This is $$$O(log^2{X})$$$ solution, which is incorrect.

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

        Nice idea. I think after that you should have realized, that building solution using independent blocks would result in very lengthy sequence. And after that realization should have abandoned this approach and returned one step back to $$$1, 2, 3, 4, ...$$$

        If we add $$$3$$$ to the end of $$$1, 2, 3, 4$$$ we would get additionally as much sequences as there were sequences in $$$1, 2, 3$$$

        So in general adding $$$m$$$ to the $$$1, 2, 3, ..., n$$$ would increase number of sequences by $$$2^m$$$. That is I believe — final idea of solution.

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

          I figured this out but was unable to implement within time :(

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

I didn't like the round (yes, I am going back to expert again)

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

is it div3?

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

Horrible statement for D!

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

Am I the only one who was struggling with problem B ;-;

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

E looks like easyer than D because you can find the solution on the Internet :)

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

OMG! Stuck on B for more than 30 minutes, not until the contest is finished did I notice that the length is $$$2^{a_i}$$$ not $$$a_i$$$ .

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

Problem E coincides with APIO2022 Problem C completely.

In APIO2022 Problem C — Permutation, It requires an array of length less than 90. In today's contest, it just has a limit that the array of length at most 200. Besides, In APIO, it also requires that elements should be distinct. It has been weakened.

I think that E<D.

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

Can someone tell me why my code for D get runtime error? Thank you in advance

My Code

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

Chinese A-E video problem solving in bilibili 【Codeforces Edu161 (A-E讲解)】 https://www.bilibili.com/video/BV1pw41177jC/?share_source=copy_web&vd_source=3e1f94fdc189dba4d4738f04ef57df8f

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

Wasted 10 minutes in Problem B before I noticed the power of 2.

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

Me thinking that D was about decreasing health instead of just checking if damage is enough. :[

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

I submitted B 5 times and got WA.Because I thinked pow(2,0)=0.:)

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

today's question was few tricky but we all enjoy this contest. Thank you

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

Can some high rated coder tell me how to become an expert asap?

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

    You just need to work on yourself. Try solving previous contests in virtual mode or just try solving problems in archive. There you can choose the types of tasks in which you are bad. If you can't solve something, don't look at the solution right away, try to solve by yourself. But if you really can't, check solution and always write your code by yourself. Also there are some useful courses in edu, you can solve them too

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

Div 2. where E solved by more than 1800 people,

bye-bye my rating 😂

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

it's okay ill try again next round. btw can i participate div1 round?

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

Can someone tell me does KasymK cheating in this round?

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

I don't understand why my hack didn't work on problem B Test: 1 4 0 0 0 3 This is withing the constraints of the input given but it shows unsuccessful hacking attempt because expected answer is 1. Shouldn't expected answer be 0 since no triangles can be formed obviously.

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

Decent contest. A and B is okay. C is somewhat fun but probably should only be limited to a<b (failed rhe caseworking like an idiot, but even then turning from the left-right variation to the other way around doesn't require much effort) Who tf allowed E to exist? Even I, a literal green, knows that it's APIO22's perm at first glance. Stealing problems from chinese OJs or some random unpopular place, while a scummy thing to do, would still only allow a small set of participant to get a major advantage. But stealing from fricking APIO??? What kind of coordinator even allowed that to exist lmao. What's next? Stealing literal IOI problems? Come on man what the hell

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

Decent contest. A and B is okay. C is somewhat fun but probably should only be limited to a<b (failed rhe caseworking like an idiot, but even then turning from the left-right variation to the other way around doesn't require much effort) Who tf allowed E to exist? Even I, a literal green, knows that it's APIO22's perm at first glance. Stealing problems from chinese OJs or some random unpopular place, while a scummy thing to do, would still only allow a small set of participant to get a major advantage. But stealing from fricking APIO??? What kind of coordinator even allowed that to exist lmao. What's next? Stealing literal IOI problems? Come on man what the hell

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

    ......and the fact that anyone who takes CP seriously should know about the existence of oj.uz, which...allows for free copy pasting, is, uhhhh, funny. Stealing from a judge that allows you to see submissions post-AC is already bad, stealing from somewhere that you could ctrl+c ctrl+v for free..... Should've copied instead of debugging C smh

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

    then why you didn't solve E?

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

      Don't want to copy code + messed up horribly (unironically know that adding a numbern that is larger than all previous corresponds to adding a 1 at the end of current bit sequence but not knowing how to deal with x2 case). What do you expect from a Green again

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

Anyone plz tell me how can you solved the Problem C or D, I was solved only A,B. Thankyou

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

    Problem C was only the cost of going to X -> X+1 -> X+2 -> ... -> Y if $$$X < Y$$$, or X -> X-1 -> X-2 -> ... -> Y if $$$X > Y$$$. The reason is that if you go back to a closest city you have to retreat anyway, so we only need to calculate the cost of going to the left, or to the right. To do this efficiently we use prefix and suffix sums.

    Problem D for me was only implementation, I simulated the steps, but instead of iterating all the monster and removing them for $$$N$$$ steps I only save the monsters that are affected by removing the dead monsters. I think this is $$$O(n \log n)$$$?, because in each iteration the monsters affected are reduced. I really don't know and possibly get hacked. For removing monsters I use Linked List.

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

      D is $$$O(n)$$$ if implemented properly because each monster is removed once = n in total, and each removed monster affects two in the next round = 2n. +n rounds = still $$$O(n)$$$.

      Something like this. My initial implementation was $$$O(N log N)$$$ improved by reading other solutions.

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

      Thanks for sharing your idea.

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

242304887

what is wrong with my solution!! this problem suck!!

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

Going back to newbie :(

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

Could someone explain why and tell me the number of increasing subsequences?

UPD: I found out why, thanks

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

I actually liked E, It took me an hour to come up with a pattern, the pattern was related to bitmask of X. It could have been better if length of array was atmost 120.

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

Can anyone tell me why my submission on D gets WA?

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

    The problem is the first occurrence of this line:

    if (i==0||been[i]) continue;
    

    If the monster on the left is missing/dead, you still need to check the monster on the right. You should combine that if-statement with the next one, instead of skipping the rest of the loop body.

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

    Take a look at Ticket 17262 from CF Stress for a counter example.

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

What does this mean "The penalty for each incorrect submission until the submission with a full solution is 10 minutes"

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

    When you commit the correct solution, you get points like you would have commited it 10 minutes * wrong times later.

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

    assume that you sent problem B after 10min and get wrong answer on test bigger than 1

    this 10min will be added to your penalty

    your handle A: +(0:03) B: -1(0:10)

    your penalty will be 3+10

    sorry for being complicated

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

    even if you send 100 wrong submissions, it doesnt count to your penalty until you submit a correct one. Each wrong submission costs 10 penalty points. A submission is not wrong if it is accepted or compilation error or your code fails in the very first test.

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

    On the scoreboard, people are ranked by number of problems solved first (higher is better), and by time second (lower is better).

    The time is the submission time of all the solutions added together. For example, if you solve problem A, B and C exactly 10, 20 and 30 minutes after the start of the contest, your total time is 60 minutes. For every incorrect submission, 10 additional minutes are added to your time.

    However, and I think this is where the confusion comes from, the penalty time for incorrect submissions only applies to problems that you have solved. If you do not solve the problem, that problem adds 0 minutes to your time, no matter how many failed attempts you made.

    This prevents situations like where Contestant 1 solves problem A in 15 minutes. Contestant 2 solves problem A in 10 minutes, and then makes a wrong attempt to solve problem B. Giving contestant 2 a 10 minute penalty would make him rank lower than 1, which seems unfair, since both participants solved the same set of problems (only A) and participant 2 was strictly faster.

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

Can Anyone please explain the logic behind Problem D ...

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

    Consider the monsters before first day. Each monster gets some damage, foreach monster you can tell how many days it lives.

    Output answers until the first day monsters die, then remove all monsters that die that day. Repeat.

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

    If you use the linked list approach, then the intuition is this: you can easily compute whether a monster dies in the current round, by adding the attack scores of its neighbors and comparing it to the monster's defense score. If the monster survives this round, it will also survive subsequent rounds, as long as its neighbors don't change.

    So the only monsters that you need to check on round X are the neighbors of the monsters that died on round (X — 1). (Round 1 is a special case: here you have to check all monsters.) If you store the monsters in a double-linked list, then you can efficiently remove dead monsters and calculate a list of their neighbors, which you use in the next round, etc.

    This way, you do at most O(N) work across all N rounds.

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

    Video editorials for D & E here: https://www.youtube.com/@rishabhxchoudhary/videos

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

Anyone knows why my submission for problem D gets wrong answer verdict? I am trying to maintain the previous and next monsters in prv[i] and nxt[i], code here: https://codeforces.com/contest/1922/submission/242332530

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

b Solution:- https://codeforces.com/contest/1922/submission/242271062 what is wrong in my code

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

How to solve F? Does it use some specific optimisation?

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

    Naive O(N^3K) dp was just fine.

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

      Can't you just bruteforce every possible x in $$$O(N x)$$$?

      Oh, I see now. That different x's are optimal, in 3rd test case replace first all 2s with 3 and then entire array to 2.

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

very bad explanation of first question

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

Why is the ans to 3rd sample testcase in F, 2?

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

Can someone explain B?

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

    we have to pick three powers a,b,c lets assume a<=b<=c. if a=b means 2^a+2^b=2^(a+1) => 100 + 100 ==> 1000 (2^3 addition in binary) the sum has to be less than longest side to have a valid triangle. which means a+1>c but c>=a so we have to take c such that it is equal to a

    if a!=b a=0100 b=1000 sum=1100 this sum is less than 10000 i.e we need c to be b<=c<b+1

    so we need to take all the pairs in which either 3 or 2 numbers are equal

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

242343507 whats up with testcase 3 in B? how can be factorial of any number be zero?

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

Can anyone explain how to approach problem D

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

Video editorials for D & E here: https://www.youtube.com/@rishabhxchoudhary/videos

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

can anyone tell me where i'm wrong in my solution for problem D? thank you.

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

Can anyone help me point out what is wrong in my 242347538 for problem D?

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

Very simple contest!!

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

still trying to solve A

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

Can someone explain why this solution 242350744 for problem C is giving runtime error on testcase 3.

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

respectfully, write better statements please.

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

E was surely much easier than D.

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

educational round is essential for college students. Try solving it and your problem solving skill will developed

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

This submission seems suspicious, the participant has included code from some other problem to avoid plag checks. His exact same code was available in a youtube video during the contest. MikeMirzayanov please look into this.

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

Problem E, Possible Issue with Judge,

Verdict: Wrong answer on test 2, test case 29

Test case 29,

30

My output for test case 29,

7

1 100000003 2 100000002 3 100000001 4

Judge: Wrong answer The number of increasing subsequences in the printed array doesn't equal to x (test case 29)

I have myself counted 30 increasing subsequences in my output. Please look into this.

242373040

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

    Ok this is really weird actually, I ran your code locally and on an online compiler for X = 30 and got the output of:

    8 100000004 1 100000003 2 100000002 3 100000001 4

    But when I ran your code on Custom Invocation on CF, I got the output that you described. Really strange.

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

      Actually follow up on this, it prints out: 8 100000004 1 100000003 2 100000002 3 100000001 4

      When compiled with G++17 but it outputs:

      7 1 100000003 2 100000002 3 100000001 4

      When compiled with G++20

      This might be your problem...

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

    The judge is correct. However, your code seems to be printing

    8
    100000004 1 100000003 2 100000002 3 100000001 4 
    

    instead of the output you mentioned for the 30 case when I run it on C++17. Here the answer is clearly > 30. But the output you mentioned in your comment will have 30 favourable subsequences.

    Curiously, I got the output you mentioned when I ran it in C++20, so you may have some kind of compiler specific error in your code.

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

    You access outside the limits of your pos array (I think you meant to put j < pos.size() in the if?).

»
4 месяца назад, # |
Rev. 4   Проголосовать: нравится +7 Проголосовать: не нравится
A hack for C
How it works
  • »
    »
    4 месяца назад, # ^ |
    Rev. 3   Проголосовать: нравится +17 Проголосовать: не нравится

    Actually there's another one. A lot of contestants don't use the prefix sum to solve C. They just calculated the distance one by one. So, the following can hack them.

    1
    100000
    ......
    100000
    1 100000
    1 100000
    ......
    1 100000
    
    The generator

    And, for problem B, there's so many people use a "cnt" array to count the appearance of a number. They just memset the cnt array in the beginning of each test case. So, just construct a test with 10000 test cases and make sure that the sum of n is 300000.

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

Guys pehle ques me toh same same but diffelent...ho gya..:)

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

I think A problem is bad,because its topic is vague

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

I feel like this contest has tested the contestant's ability to judge time complexity 感觉这场就考验了选手对时间复杂度的判断能力

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

Wow, 3 years since I last did competitive programming and I still choke under pressure of a CF contest XD

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

Can anyone tell me a case where it is failing in B





int n; cin>>n; vi v(n); for(auto &it : v)cin>>it; map<int, int>mp; sort(al(v)); map<int, int>smaller; int cnt = 0, prev = -1; set<int>st; for(auto &it : v) { st.insert(it); mp[it]++; if(prev != it) { prev = it; smaller[it] = cnt; } cnt++; } debug(mp); debug(smaller); int ans = 0; for(auto &it : st) { int f = mp[it]; int cur = 0; if(f >= 3) { int NCR = ncr(f, 3); debug(NCR); cur += NCR; } if(f >= 2) cur += smaller[it]; ans += cur; } cout<<ans<<endl;
  • »
    »
    4 месяца назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    either 3 sides have to be same. (or) 2 sides have to be same and 1 side have to be lessthan other equal sides. ~~~~~ reason: In a triangle, sum of 2 sides have to be more than 3rd side. ~~~~~ As we are given in powers of 2, if 3 sides are different, then count of triangles are 0. if 2 sides are same, count = choose 2 of same size and other with size less than choosen size. if 3 sides are same, count = choose 3 from same size.

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

this is code, i have written for E (Increasing Subsequences)

vector<int> solve(ll n){
    vector<int> v{1}; vector<ll> dp{2};
    while(dp.back()*2<=n){
        v.push_back(v.back()+1); 
        dp.push_back(dp.back()*2);
    }
    ll cs = dp.back(); int l = v.back();
    vector<pair<int, int>> ins; int s = v.size();
    while(cs<n){
        if(cs+1==n){
            l++;
            ins.push_back({l, 0});
            cs++; break;
        }
        for(auto it = dp.rbegin();it!=dp.rend(); it++){
            if(cs+*it <= n){
                cs+=*it;l++;
                ins.push_back({l, s-(distance(dp.rbegin(), it))});
                break;
            }
        }
    }
    for(auto &i: ins){
        int val = i.first; int p = i.second;
        v.insert(v.begin()+p, val);
    }
    return v;
}

Its running perfectly fine in my local device.

when submitted, i came to see that I got wrong answer when n=pow(10, 18). i checked my solution with the code:

ll count_seq(vector<int> v){
    int n = v.size();
    vector<ll> dp(n, 1);
    for(int i = 0;i<n;i++){
        for(int j = 0;j<i;j++){
            if(v[j]>=v[i]) continue;
            dp[i]+=dp[j];
        }
    }
    return accumulate(dp.begin(), dp.end(), 1ll);
}

I sent output of solve function as input to count_seq function. I am getting pow(10, 18) implying its correct answer.

I cant figure out whats wrong. please help me.

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

For D when i run my code in VScode for the example testcase i am getting correct answer but when i submit or use the custom invocation i am getting wrong answer for the same testcase. Does anyone know the reason?. My Code.

  • »
    »
    4 месяца назад, # ^ |
    Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

    Your code contains an UB. In the following code block:

    for(auto itd = defence.begin(), ita = attack.begin(); itd != defence.end(); itd++, ita++){
        if(*itd < 0){
            died++;
            defence.erase(itd);
            attack.erase(ita);
            itd--;
            ita--;
        }
    }
    

    You tried to erase 2 iterators called itd and ita, but you immediately use them after the erasing. It is now allowed and that's why there are different output of your code.

    To correct, you should create a temporary backup for prev(itd), prev(ita) and then erase itd, ita. Finally, replace itd, ita with the previous backup.

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

      Thanks for the reply. i found one more problem which was the reason for different output was in the first if block

      for(int i = 0; i < k; i++){
          if(i == 0 && (defence[0] - attack[1] < 0))
              defence[0] -= attack[1];
                      
          else if(i != k-1 && (defence[i] - (attack[i-1] + attack[i+1]) < 0))
              defence[i] -= (attack[i-1] + attack[i+1]);
      

      even when i = 0, the if statement is not executing because of the '&&' statement and the else if statement is running for 0 index and subtracting '-1 th' index which gives it a garbage value.

      what you suggested is another problem which i need to correct so thanks for that. so will this work??--

      for(auto itd = defence.begin(), ita = attack.begin(); itd != defence.end(); itd++, ita++){
          if(*itd < 0){
              died++;
              auto prev_itd = itd - 1;
              auto prev_ita = ita - 1;
              defence.erase(itd);
              attack.erase(ita);
              itd = prev_itd;
              ita = prev_ita;
          }
      }
      
      • »
        »
        »
        »
        4 месяца назад, # ^ |
        Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

        I think the following will be better:

        for(auto itd = defence.begin(), ita = attack.begin(); itd != defence.end(); ){
            if(*itd < 0){
                died++;
                auto tmp_itd = itd;
                auto tmp_ita = ita;
                defence.erase(itd);
                attack.erase(ita);
                itd = tmp_itd;
                ita = tmp_ita;
            } else {
                itd++;
                ita++;
            }
        }
        

        Your updated code still have some problem. If the itd points the first element of defence, you cannot to set the prev_itd to itd - 1.

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

Problem C.

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

How long does it take for the rating to get updated after a contest?

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

    Because it is O(n^2)
    Think what happens if no one ever dies

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

    The time complexities of your two codes in the worst condition (i.e. No one dies) are both $$$O(Tn^2\log n)$$$. It will get TLE obviously. To improve, you can check my submission. We should avoid useless check of whether a monster dies when its left and right neighbours don't die.

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

When does the system testing start?

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

Video solutions for A-C, D-E

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

Really wondering if this solution for F is hackable (in both idea and execution time)? I know it had to be DP but the presented idea seems pretty messy and duct-taped, would actually be open to some revelations, and the complexity seems to be a pretty high-constant-factor $$$O \left( n^3 x \right)$$$.

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

Finally Expert !!!

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

Strange, I got TLE for my submission for B despite it being O(nlogn) in worst case.

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

242432261 Can anyone explain why this code is giving WA on testcase 5

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

can anuone help me. I have written the code for problem D with linkedlist and its working properly for test1. But, I am getting runtime error: "-1073741819 exit code" for test2 . what should i do.

The test case details are in https://codeforces.com/contest/1922/submission/242434985

my code:


// object of linked list class obj{ public: int a, d; // attack and defend values obj* next{nullptr}; obj* prev{nullptr}; //next and previous monsters obj(int at, int de, obj* p, obj* n=nullptr){ a=at, d=de; prev=p;next=nullptr; } }; bool check(obj* curr){ // checks if current monster will be deleted if(curr->prev==nullptr && curr->next==nullptr) return false; else if(curr->prev==nullptr){ if(curr->d<curr->next->a) return true; else return true;} else if(curr->next==nullptr){ if(curr->d < curr->prev->a) return true; else return false; }else{ if(curr->d < curr->prev->a + curr->next->a) return true; return false; } } int main(int argc, char const *argv[]) { int T; cin>>T; while(T--){ int n;cin>>n; vector<int> A(n, 0), D(n, 0); // A for attack and D for defend for(int i = 0;i<n;i++) cin>>A[i]; for(int i = 0;i<n;i++) cin>>D[i]; obj* head = new obj(A[0], D[0], nullptr); obj* l = head; for(int i = 1;i<n;i++){ l->next=new obj(A[i], D[i], l); l=l->next; } deque<obj*> next_del;// contains all monsters that are going to be deleted in next round for(auto t = head; t!=nullptr; t=t->next){ if(t->prev==nullptr && t->next==nullptr){ }else if(t->prev==nullptr){ if(t->d < t->next->a) next_del.push_back(t); }else if(t->next==nullptr){ if(t->d < t->prev->a) next_del.push_back(t); }else{ if(t->d < t->prev->a + t->next->a) next_del.push_back(t); } } vector<int> ans; while(next_del.size()){ ans.push_back(next_del.size()); set<obj*> altered; // contains all monsters that needs to be checked. while(next_del.size()){ obj* front = next_del.front(); next_del.pop_front(); obj* prev = front->prev; obj* next = front->next; while(next_del.size() && next_del.front()==next){ next_del.pop_front(); next=next->next; } for(obj* ob = front;ob && ob!= next;){ obj* ppp = ob; if(ob)ob=ob->next; if(ppp) delete ppp; } if(prev) altered.insert(prev); if(next) altered.insert(next); if(prev) prev->next=next; if(next) next->prev=prev; } next_del.clear(); for(auto &i: altered){ if(check(i)) next_del.push_back(i); } } while(ans.size()<n) ans.push_back(0); for(auto &i: ans) cout<<i<<" "; cout<<"\n"; } }
  • »
    »
    4 месяца назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    Try not to use pointers. In CP, using arrays prev and next will be better than using pointers. You can check my submission to see how to use arrays instead of pointers..

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

    I found where's wrong in your code now. Here's the updated version.

    There are two modifies. The first is to remove the block:

    while(next_del.size() && next_del.front()==next){
        next_del.pop_front(); next=next->next;
    }
    for(obj* ob = front;ob && ob!= next;){
        obj* ppp = ob;
        if(ob)ob=ob->next; if(ppp) delete ppp; 
    }
    

    and add the following:

    front->prev=nullptr;
    front->next=nullptr;
    

    The second is correcting the check function. If curr->prev==nullptr satisfies, we should execute if(curr->d<curr->next->a) return true; else return false; but not if(curr->d<curr->next->a) return true; else return true;. (Pay attention to the last word)

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

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

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
void solve() {
    ll n;
    cin>>n;
    vector<ll> arr(n+1);
    for(ll i=1;i<=n;i++){
        cin>>arr[i];
    }
    vector<ll> close(n+1);
    close[1]=2;
    close[n]=n-1;
    for(ll i=2; i<n; i++){
        if(abs(arr[i]-arr[i-1])<abs(arr[i]-arr[i+1])){
            close[i]=i-1;
        }
        else{
            close[i]=i+1;
        }
    }

    vector<ll> dist;
    for(ll i=1;i<n;i++){
        if(close[i]==i+1){
            dist.pb(1);
        }
        else{
            dist.pb(abs(arr[i]-arr[i+1]));
        }
    }

    vector<ll> backDist;
    for(ll i=n;i>1;i--){
        if(close[i]==i-1){
            backDist.pb(1);
        }
        else{
            backDist.pb(abs(arr[i]-arr[i-1]));
        }
    }

    reverse(backDist.begin(),backDist.end());

    vector<ll> prefixSum(dist.size()+1);
    vector<ll> suffixSum(dist.size()+1);

    prefixSum[0]=0;
    prefixSum[1]=dist[0];

    suffixSum[dist.size()]=0;
    suffixSum[dist.size()-1]=backDist[dist.size()-1];




    for(ll i=2;i<=dist.size();i++){
        prefixSum[i]=prefixSum[i-1]+dist[i-1];
    }

    for(ll i=dist.size()-2;i>=0;i--){
        suffixSum[i]=suffixSum[i+1]+backDist[i];
    }

    ll q;
    cin>>q;
    vector<ll> res;
    while(q--){
        ll x,y;
        cin>>x>>y;
        if(x<y){
            ll ans = prefixSum[y-1]-prefixSum[x-1];
            res.pb(ans);
        }
        else{
            ll ans = suffixSum[y-1]-suffixSum[x-1];
            res.pb(ans);
        }
    }
    for(ll i=0;i<res.size();i++){
        cout<<res[i]<<endl;
    }

}

Can anyone help me find why this code is giving runtime error in testcase-2

Problem-C

PLease help !!!

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

    When $$$n=2$$$, dist only contains 1 element. Then, prefixSum[1]=dist[0]; and suffixSum[dist.size()-1]=backDist[dist.size()-1]; will cause an RE.

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

      when n=2

      suffixSum[dist.size()-1] = backDist[dist.size()-1];
      

      that is

      suffixSum[0]=backDist[0]
      

      i dont get how it will cause RE can you explain a little

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

        My mistake. Actually it's here:

        for(ll i=dist.size()-2;i>=0;i--){
            suffixSum[i]=suffixSum[i+1]+backDist[i];
        }
        

        dist.size() will return a size_t (a.k.a unsigned long long or unsigned long, depend on your machine and compiler) type. Then, minus it with $$$2$$$, we'll get a very large number ($$$18446744073709551615$$$ or $$$4294967295$$$). Then let i be that and try visit suffixSum[i]. It will cause the RE here.

        To correct, just change dist.size()-2 to (int)dist.size()-2. This convert the unsigned long long to int.

        I've modified your solution and it's AC now.

        BTW it's very weird that you've submitted an AC solution but then submitted an RE one! And that two codes are so similar.

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

          Thanks ohhh i was trying to figure out why my code is giving RE that's why i was trying to submit different codes

          just got a little pissed as i wasn't able to submit in the contest

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

For problem C, I can't understand I just can get AC in contest even though I finish n queries in each test case rather than m queries :(

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

    That's because the pretests are too weak. In fact, in this round, C's pretests are the weakest one as there's more than 100 hacks about problem C.

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

Problem A Statement Was Too Confusing

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

downvote, if you liked editorial

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

Good luck to everyone!

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

Why do you only takes 3 problems to the problem list?

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

W