I_love_Leyeli_Meredova's blog

By I_love_Leyeli_Meredova, history, 7 weeks ago, In English

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!

»
7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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
  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    codeforces output
    my output

    you can check it

    • »
      »
      »
      7 weeks ago, # ^ |
        Vote: I like it +10 Vote: I do not like it

      I corrected and got accepted with your code.

      Corrected Find Function
      • »
        »
        »
        »
        7 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

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

        • »
          »
          »
          »
          »
          7 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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;