hello everyone,goodEvening…i was doing UPDATEIT question from spoj.This is my very first question on Binary indexed trees.I am getting repetitive TLE.Can anybody check this…Thanks a lot… solution link
Use scanf() and printf() and you’ll get AC. I coded the very same but used stdio i/o. If you still get TLE, just ask here.
See line 9 in your code,
for(;k<=n;k+= (k&(-k))); // note semicolon here ft[k]+=v; // this statement gets executed only for the last k when whole of the for loop is executed due to the semicolon. This is the mistake in your code.
All the best!
You can also add the following line at the start of main():
Before every operation you need to increase the index by 1 just because we use base indexing 1 in FT. Hope this helps
Use BIT to solve this question.
@damn_me thanks…I figured out what was wrong.Actually i made ft as global array which remains same for all testcases.Filling it again with 0 helped me thanks a lot
it still gives tle…i think my logic is wrong
Sorry but I didn’t get you can you please elaborate…not even getting which part of code you are talking about…Anyway thanks
@doodle90 Correct line 9 in your code(see semicolon there, it shouldn’t be).
@damn_me thanks(as always) :)…if your code is that similar to mine and you got Ac…can you please share your code because i am getting repetitively wrong answers.Don’t know where i am going wrong…Or please try submitting my code from your account
@doodle90 My code, z9kb5I - Online C++0x Compiler & Debugging Tool - Ideone.com If still unable to rectify, you may ask here… Remember keeping long long int for query function.
@mansigupta19 Did you see the code? He has used BIT only…