For this Question: <b> The only difference between the easy and the tricky version is the constraint on the number of queries Q. Solving the tricky version automatically solves the easy version.</b> 

You are given an array A of N integers. You will be given Q queries with two integers L and R. For each query, you need to find the sum of all elements of the array excluding the elements in the range [L, R] (both inclusive) modulo 10<sup>9</sup>+7.The first line of the input contains an integer N, the size of the array.
The second line of the input contains N integers, the elements of the array A.
The third line of the input contains an integer Q.
The next Q lines contain two integers L and R.

Constraints
1 <= N <= 200000
1 <= A[i] <= 1000000000
1 <= Q <= 100000
1 <= L <= R <= NOutput Q lines, each having a single integer the answer to Q-th query modulo 10<sup>9</sup>+7.Sample Input
4 
5 3 3 1
2
2 3
4 4

Sample Output
6
11

Explanation: The array A = [5, 3, 3, 1].
First Query: Sum = 5 + 1 = 6.
Second Query: Sum = 5 + 3 + 3 = 11, I have written this Solution Code: n = int(input())
arr = list(map(int ,input().rstrip().split(" ")))
temp = 0
modified = []
for i in range(n):
	temp = temp + arr[i]
	modified.append(temp) 

q = int(input())
for i in range(q):
	s = list(map(int ,input().rstrip().split(" ")))
	l = s[0]
	r = s[1]
	sum = 0
	sum = ((modified[l-1]-arr[l-1])+(modified[n-1]-modified[r-1]))%1000000007
	print(sum), In this Programming Language: Python, Now tell me if this Code is compilable or not?