lohitpt252003's blog

By lohitpt252003, history, 6 months ago, In English

You are given an arr (len(arr) <= 1e5) (-1e9 <= arr[i] <= 1e9) and q (<= 1e5) queries, now each query is of the form, (l, r, x) (1 <= l <= r <= len(arr), x can be any 32 bit integer) for each query u need to output the sum(arr[i]) such that l <= i <= r and arr[i] >= x.

I am stuck with this problem can anyone solve this problem?

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

»
6 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

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

»
6 months ago, hide # |
Rev. 2  
Vote: I like it +23 Vote: I do not like it

sort the queries to the decreasing of x and sort the array decreasing and use segment tree (ofc you need to save the original index of the queries and the array).

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it -22 Vote: I do not like it

    Can u please write the code?

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it +7 Vote: I do not like it

      I think this should work.

      Code

      On the test:

      1
      4 4
      1 2 3 4
      1 3 2
      2 3 2
      2 3 4
      1 4 2
      

      It prints:

      5
      5
      0
      9
      
    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
  • »
    »
    10 days ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    why u so good bro