yswartz's blog

By yswartz, history, 7 years ago, In English

I am getting TLE in test case 11 in this 35599469 problem. Is there any way to increase every value of an array by some value without running any loop?

  • Vote: I like it
  • +2
  • Vote: I do not like it

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

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

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Take an extra variable say, bonus

For each type 2 update increase bonus by y

Then for each query on ith index it is  = a[i] + bonus

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    Also when dealing with type 1 operation, replace the v-th with "x — bonus" not "x".

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

I don't have time to see your submission, but you can use any range query data structure like BIT, or segment tree. But this problem is not that difficult, see the editorial.