Hoa_Dau_Biec's blog

By Hoa_Dau_Biec, history, 7 weeks ago, In English

Hi guy, i am stucking in this problem : https://cses.fi/problemset/task/1735/

Here is my code : https://cses.fi/paste/567abb6bc35edc71146fae/

I have no idea why i got WA. Can anybody explain for me what was wrong in my concept ?

(Sorry because my English:"((( )

UPD : I got AC, my code has a big mistake follow smax said below.

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

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

Lines 50-53:

it[l].sum = it[id].sv*(mid-st+1);
it[r].sum = it[id].sv*(se-mid);
it[l].ic = it[r].ic = 0;
it[id].sv = 0;

You set the left and right child's sums, but then you don't propagate it[id].sv to it[l].sv and it[r].sv, so any children underneath the left and right children don't get set properly.

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

    That works! Thank you very much. I was checked it as careful as I can. But it still has a big mistake. Thank you again!

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

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