Given array find number of triplets with sum in given range

In the problem, we are given an array and we need to find triplets which have their sum in the given range. I found that this can be done in O(n2) Like this!!. Is there any way to do it faster like in O(n) or O(nlogn)?