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

Автор I_love_Leyeli_Meredova, история, 3 месяца назад, По-английски

Hello Codeforces!

Today I was solving one problem from codeforces edu

My code

Can someone tell me how I can solve this problem? (Sorry for my English)

Thanks!

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

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

Let's change the problem statement, find the prefix where the sum is k+1(since it starts counting from 0), now it's a famous problem with segment trees, and try to solve it for the general case(not 01) assuming there always exists a prefix

but for this problem in particular(I'm not going to solve the question above but give another approach(which is kinda similar))

Build logic
get logic

for the update function, it's like incrementing a[i] by 1,-1 which you should be able to do, but in case not:

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

    thank you but everything you said I have already done in my program.

    codeforces output
    my output

    you can check it

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

      I corrected and got accepted with your code.

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

        Oh my God, thank you, but could you explain to me why this is the right

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

          the since the big find function(the actual one) returns a number, in the second one you're calling it and it does it's job perfectly fine, but you're not returning it.

          take this:

          ll add(ll i, ll j) { return i + j; }
          
          add(10, 15);
          

          and expecting the code to output 25,

          instead you should've used cout << add(10, 15) << endl;