AllForCode's blog

By AllForCode, history, 91 minute(s) ago, In English

I came up with this problem recently but haven't been able to find an efficient approach. Since it's a self-created problem, I don't have official test cases. Problem Statement There is a sequence a of n integers. Process q queries given in order. For q-th query, you are given integers l, r (1 <= l <= r <= n) and a integer x.Perform the following in order: Add x for each of a[l], a[l + 1],.., a[r]. Let m = r - l + 1, and b = (b[1], b[2],.., b[m]) = (a[l], a[l + 1],.., a[r]) and sort(b + 1, b + m + 1). Present the results of (m * b[1] + (m - 1) * b[2] + .. + b[m]) % MOD (MOD = 1e9 + 7) (n <= 1e5, q <= 1e5, |a[i]| <= 1e9) I can't think of a specific time limit for this problem either, but can you find the quickest way to solve it?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
90 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
87 minutes ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
75 minutes ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Well, I guess this is lazy segment tree. Please correct me if I'm wrong. Edit: Nevermind, I think I misunderstood the problem.