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: import java.io.*;
import java.util.*;



class Main {
	  static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(
                new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    if (cnt != 0) {
                        break;
                    }
                    else {
                        continue;
                    }
                }
                buf[cnt++] = (byte)c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0,
                                 BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	public static void main (String[] args) throws IOException {

        Reader sc = new Reader();
		int arrSize = sc.nextInt();
		long[] arr = new long[arrSize];

		for(int i = 0; i < arrSize; i++)
		{
			arr[i] = sc.nextLong();
		}

		long[] prefix = new long[arrSize];
		prefix[0] = arr[0];
		for(int i = 1; i < arrSize; i++)
		{
			long val = 1000000007;
			prefix[i - 1] %= val;
			long prefixSum = prefix[i - 1] + arr[i];
			prefixSum %= val;
			prefix[i] = prefixSum;
		}

		long[] suffix = new long[arrSize];
		suffix[arrSize - 1] = arr[arrSize - 1];
		for(int i = arrSize - 2; i >= 0; i--)
		{
			long val = 1000000007;
			suffix[i + 1] %= val;
			long suffixSum = suffix[i + 1] + arr[i];
			suffixSum %= val;
			suffix[i] = suffixSum;
		}











		int query = sc.nextInt();

		for(int x = 1; x <= query; x++)
		{
			int l = sc.nextInt();
			int r = sc.nextInt();
			long val = 1000000007;
			long ans = 0;

			ans += (l != 1 ? prefix[l-2] : 0);
			ans %= val;
			ans += (r != arrSize ? suffix[r] : 0);
			ans %= val;
			System.out.println(ans);
		}
	}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not?