Автор awoo, история, 2 года назад, По-русски

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

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

Hopefully I reached Expert :)

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

I wish everyone a good contest!

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

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

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

Good Luck and Have Fun everyone!

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

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

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

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

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

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

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

Hopefully I can get Pupil(not Newbie) :/

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

BledDest Round

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

Lets, Hope I can get Expert color.

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

Hope I can get Expert badge.

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

Hopefully I reached Specialist :)

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

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

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

Educational round is overrated

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

Educational round means you have to study gcd well :)

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

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

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

bad explanation of first question

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

[deleted]

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

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

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

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

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

I have skill issue

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

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

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

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

I have skill issue

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

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

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

Wasted too much time in problem A :/

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

can someone please explain problem A? Thanks in advance.

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

awoo Loved the D and people think LinkedList is overrated.

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

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

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

my first E yaaaaaaaaaaay

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

Anyone feel like the wording on A was weird?

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

what is the approach for B?

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

E was basically APIO 2022 P3 with nerfed limits?

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

How to solve F?

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

Good contest

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

I submitted B 14 times ;-;

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

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

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

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

How to guess the solution of problem E?

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

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

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

is it div3?

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

Horrible statement for D!

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

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

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

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

»
2 года назад, скрыть # |
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$$$ .

»
2 года назад, скрыть # |
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.

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

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

My Code

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

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

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

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

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

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

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

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

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

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

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

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

bye-bye my rating 😂

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

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

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

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

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

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

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

    Problem C was only the cost of going to X -> X+1 -> X+2 -> ... -> Y if $$$X \lt Y$$$, or X -> X-1 -> X-2 -> ... -> Y if $$$X \gt 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.

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

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

242304887

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

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

Going back to newbie :(

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

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

UPD: I found out why, thanks

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

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

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

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

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

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

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

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

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

  • »
    »
    2 года назад, скрыть # ^ |
    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.

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

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

  • »
    »
    2 года назад, скрыть # ^ |
    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.

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

»
2 года назад, скрыть # |
 
Проголосовать: нравится 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://mirror.codeforces.com/contest/1922/submission/242332530

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

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

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

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

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

Can someone explain B?

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

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

Can anyone explain how to approach problem D

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

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

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

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

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

Very simple contest!!

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

still trying to solve A

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

E was surely much easier than D.

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

»
2 года назад, скрыть # |
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

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

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

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

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

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

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

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

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

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

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

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

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

Problem C.

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

When does the system testing start?

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

Video solutions for A-C, D-E

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

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

Finally Expert !!!

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

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

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

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

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

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

downvote, if you liked editorial

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

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