The only difference between easy and hard versions is on constraints. In this version constraints are higher. You can make hacks only if all versions of the problem are solved.

Koa the Koala is at the beach!

The beach consists (from left to right) of a shore, $n+1$ meters of sea and an island at $n+1$ meters from the shore.

She measured the depth of the sea at $1, 2, \dots, n$ meters from the shore and saved them in array $d$. $d_i$ denotes the depth of the sea at $i$ meters from the shore for $1 \le i \le n$.

Like any beach this one has tide, the intensity of the tide is measured by parameter $k$ and affects all depths from the beginning at time $t=0$ in the following way:

  For a total of $k$ seconds, each second, tide increases all depths by $1$.

  Then, for a total of $k$ seconds, each second, tide decreases all depths by $1$.

  This process repeats again and again (ie. depths increase for $k$ seconds then decrease for $k$ seconds and so on ...).

Formally, let's define $0$-indexed array $p = [0, 1, 2, \ldots, k - 2, k - 1, k, k - 1, k - 2, \ldots, 2, 1]$ of length $2k$. At time $t$ ($0 \le t$) depth at $i$ meters from the shore equals $d_i + p[t \bmod 2k]$ ($t \bmod 2k$ denotes the remainder of the division of $t$ by $2k$). Note that the changes occur instantaneously after each second, see the notes for better understanding. 

At time $t=0$ Koa is standing at the shore and wants to get to the island. Suppose that at some time $t$ ($0 \le t$) she is at $x$ ($0 \le x \le n$) meters from the shore:

  In one second Koa can swim $1$ meter further from the shore ($x$ changes to $x+1$) or not swim at all ($x$ stays the same), in both cases $t$ changes to $t+1$.

  As Koa is a bad swimmer, the depth of the sea at the point where she is can't exceed $l$ at integer points of time (or she will drown). More formally, if Koa is at $x$ ($1 \le x \le n$) meters from the shore at the moment $t$ (for some integer $t\ge 0$), the depth of the sea at this point  — $d_x + p[t \bmod 2k]$  — can't exceed $l$. In other words, $d_x + p[t \bmod 2k] \le l$ must hold always.

  Once Koa reaches the island at $n+1$ meters from the shore, she stops and can rest.

Note that while Koa swims tide doesn't have effect on her (ie. she can't drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won't drown there). 

Koa wants to know whether she can go from the shore to the island. Help her!


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 10^4$)  — the number of test cases. Description of the test cases follows.

The first line of each test case contains three integers $n$, $k$ and $l$ ($1 \le n \le 3 \cdot 10^5; 1 \le k \le 10^9; 1 \le l \le 10^9$) — the number of meters of sea Koa measured and parameters $k$ and $l$.

The second line of each test case contains $n$ integers $d_1, d_2, \ldots, d_n$ ($0 \le d_i \le 10^9$)  — the depths of each meter of sea Koa measured.

It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.


-----Output-----

For each test case:

Print Yes if Koa can get from the shore to the island, and No otherwise.

You may print each letter in any case (upper or lower).


-----Example-----
Input
7
2 1 1
1 0
5 2 3
1 2 3 2 2
4 3 4
0 2 4 3
2 3 5
3 0
7 2 3
3 0 2 1 3 0 1
7 1 4
4 4 3 0 2 4 2
5 2 3
1 2 3 2 2

Output
Yes
No
Yes
Yes
Yes
No
No



-----Note-----

In the following $s$ denotes the shore, $i$ denotes the island, $x$ denotes distance from Koa to the shore, the underline denotes the position of Koa, and values in the array below denote current depths, affected by tide, at $1, 2, \dots, n$ meters from the shore.

In test case $1$ we have $n = 2, k = 1, l = 1, p = [ 0, 1 ]$.

Koa wants to go from shore (at $x = 0$) to the island (at $x = 3$). Let's describe a possible solution:

  Initially at $t = 0$ the beach looks like this: $[\underline{s}, 1, 0, i]$.  At $t = 0$ if Koa would decide to swim to $x = 1$, beach would look like: $[s, \underline{2}, 1, i]$ at $t = 1$, since $2 > 1$ she would drown. So Koa waits $1$ second instead and beach looks like $[\underline{s}, 2, 1, i]$ at $t = 1$.  At $t = 1$ Koa swims to $x = 1$, beach looks like $[s, \underline{1}, 0, i]$ at $t = 2$. Koa doesn't drown because $1 \le 1$.  At $t = 2$ Koa swims to $x = 2$, beach looks like $[s, 2, \underline{1}, i]$ at $t = 3$. Koa doesn't drown because $1 \le 1$.  At $t = 3$ Koa swims to $x = 3$, beach looks like $[s, 1, 0, \underline{i}]$ at $t = 4$.  At $t = 4$ Koa is at $x = 3$ and she made it! 

We can show that in test case $2$ Koa can't get to the island.

Difficulty: interview

Starter code:

Solutions:
#
#    ------------------------------------------------
#           ____          _     Generatered using
#          / ___|        | |
#         | |    __ _  __| | ___ _ __  ______ _
#         | |   / _` |/ _` |/ _ \ '_ \|_  / _` |
#         | |__| (_| | (_| |  __/ | | |/ / (_| |
#          \____\____|\____|\___|_| |_/___\____|
#
#      GNU Affero General Public License v3.0
#    ------------------------------------------------
#    Author   : prophet
#    Created  : 2020-07-24 11:19:20.229238
#    UUID     : dFs0Ek0q78tkOXbf
#    ------------------------------------------------
#
production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = list(map(int, list(next_line)))
        elif input_format == 5: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))
    elif output_format == 3: formatted_output = "".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)
flip = lambda a: (a + 1) & 1

def mapl(iterable, format = 0):
    
    if format == 0: return list(map(int, iterable))
    elif format == 1: return list(map(str, iterable))
    elif format == 2: return list(map(list, iterable))
#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#


def solve():

    n, k, l = input(1)
    d = input(1)

    log(k, l)
    log(d)

    f = [l - i for i in d]

    log(f)

    p = [(0, 2 * k - 1)]

    for i in f:
        a, b = p[-1]
        if i >= k:
            p.append((0, 2 * k - 1))
        else:
            fb = k + i
            fa = max(a + 1, k - i)
            log(i, fb, fa)
            if fb < fa:
                out("No")
                return

            p.append((fa, fb))
        log(p)
    else:
        out("Yes")

    log("")
    return


for i in range(input(11)): solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


for _ in range(int(input())):
    n, k, l = list(map(int, input().split()))
    dd = list(map(int, input().split()))
    t = 0
    curld = 0
    di = False
    for d in [-(2**30), *dd]:
        if d > l:
            break
        ld = l - d
        if d + k <= l:
            curld = ld
            di = False
            continue
        if di:
            if ld >= curld + 1:
                curld += 1
            else:
                break
        else:
            curld = min(curld - 1, ld)
            if curld == 0:
                di = True
    else:
        print('Yes')
        continue
    print('No')


import sys
import os,io
input = sys.stdin.readline
# input_all = sys.stdin.read
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# input_all = io.BytesIO(os.read(0,os.fstat(0).st_size)).read
def read_int():
	return map(int, input().split())
def read_list():
	return list(map(int, input().split()))
def print_list(l):
	print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import deque as dq
# from collections import defaultdict as dc 
# import math

# f = open('test.py')
# input = f.readline
# input_all = f.read


N = int(input())
for _ in range(N):
	n, k, l = read_list()
	d = read_list()
	if max(d)>l:
		print('No')
	else:

		# print(dic)
		flag = True
		tt = 2*k
		now = tt
		for i in range(n):
			if d[i]+k<=l:
				tmp = tt
			else:
				tm = d[i]+k-l
				tmp = [tm,2*k-tm]
			# print(tmp)
			# tmp = dic[d[i]]
			if tmp==tt:
				now = tt
			elif now==tt:
				now = tmp
			else:
				now = [max(now[0]+1,tmp[0]),min(now[1]+1,tmp[1])]
				if now[0]>now[1]:
					flag = False
					break
		if flag:
			print('Yes')
		else:
			print('No')

for h in range(int(input())):
    n, k, l = list(map(int, input().strip().split()))
    
    arr = list(map(int, input().strip().split()))
    
    
    dp = [0 for i in range(len(arr)+1)]
    dp[0] = -1
    
    # print(p)
    
    there = True
    
    for i in range(len(arr)):
        if arr[i] > l:
            there = False
            break
        elif arr[i]+k > l:
            dp[i+1] = arr[i]
        else:
            dp[i+1] = -1
    
    if there == False:
        print("No")
        continue
    pointer = 0
    
    for i in range(n+1):
        if dp[i] == -1:
            if i == n:
                continue
            elif i < n:
                maxi = l-dp[i+1]
                pointer = -maxi-1
        else:
            pointer += 1
            if dp[i] + abs(pointer) > l:
                if pointer >= 0:
                    there = False
                    break
                else:
                    pointer = -(l-dp[i])
    
    if there == False:
        print("No")
    else:
        print("Yes")
            
    
    
    


import sys, os.path
from collections import deque
from fractions import Fraction as f
def IO():
    if os.path.exists('input.txt'):
        sys.stdin = open('input.txt', 'r')
        sys.stdout = open('output.txt', 'w')
    else:
        input=sys.stdin.readline
        print=sys.stdout.write
def nextInt():
    return int(input())
def nextTuple():
    return [int(a) for a in input().split()]
def nextArray():
    return list(map(int, input().split()))
def nextLine():
    return input()
def nextStringArray():
    return list(input().split())
IO()

'''code starts here'''

t=int(input())
for _ in range(t):
    n,k,l=[int(x) for x in input().split()]
    a=list(map(int,input().split()))
    flag=0
    count=-1
    for i in range(n):
        if a[i]>l:
            flag=1
            break
    for i in range(n):
        if a[i]+k>l:
            if count==-1:
                count=k+(a[i]+k)-l
                continue
            count+=1
            count=count%(2*k)
            if count<=k:
                if a[i]+count>l:
                    flag=1
                    break
            else:
                now=k+(a[i]+k)-l
                count=max(count,now)
        else:
            count=-1
    if flag==1:
        print("No")
    else:
        print("Yes")

import sys
import collections  
def input():
	return sys.stdin.readline().rstrip()
 
def split_input():
	return [int(i) for i in input().split()]

# tests = 1
tests = int(input())

for _ in range(tests):
	n,k,l = split_input()
	d = split_input()
	newd = [l - i for i in d]
	if min(newd)<0:
		print("No")
		continue
	kvalue = newd[0]
	dec = True
	ans = True
	# print(newd)
	i = 1
	while i < n:
		# print(kvalue,dec)
		if newd[i] < 0:
			ans = False
			break
		if newd[i] >= k:
			if i < n - 1:
				kvalue = newd[i+1]
				dec = True
				i += 2
				continue
		if kvalue == 0:
			dec = False
		if dec: 
			if newd[i] < kvalue:
				kvalue = newd[i]
			else:
				kvalue -= 1
		else:
			if newd[i] <= kvalue:
				ans = False
				break
			else:
				kvalue += 1
		i += 1
	if ans:
		print("Yes")
	else:
		print("No")




import math
######################################################
# ps template
def mi(): return list(map(int, input().split()))
def ii(): return int(input())
def li(): return list(map(int, input().split()))
def si(): return input().split()

#######################################################
t = ii()
for _ in range(t):
    n, k, l = mi()
    a = li()
    dp = [ -1 for i in range(n)]
    ans = True
    rev = False
    if a[0]+k<=l:
        dp[0] = 'F'
    elif a[0]<=l:
        dp[0] = l - a[0]
        if dp[0] > 0:
            rev = True
        else:
            rev = False
    else:
        dp[0] = -1
    for i in range(1,n):
        if dp[i-1]==-1 or a[i]>l:
            ans = False
            break
        if a[i]+k<=l:
            dp[i] = 'F'
        elif dp[i-1]=='F':
            dp[i] = l - a[i]
            if dp[i]>0:
                rev = True
            else:
                rev = False
        elif rev:
            if l-a[i]<=dp[i-1]-1:
                dp[i] = l - a[i]
                if dp[i]>0:
                    rev = True
                else:
                    rev = False
            else:
                dp[i] = dp[i-1] - 1
                if dp[i]>0:
                    rev = True
                else:
                    rev = False
        elif dp[i-1]+1+a[i]<=l:
            dp[i] = dp[i-1]+1
            if dp[i] == k:
                rev= True
        else:
            ans = False
            break
    #print(dp)
    if ans and dp[n-1]!=-1:
        print("Yes")
    else:
        print('No')



f=lambda:map(int,input().split())
t,=f()
for _ in[0]*t:
    n,k,l=f();s=[*f()];a=0;z=k-1
    for i in s:
        if i+k<=l:z=k-1
        elif z>=0and l>=i:z=min(z,l-i)-1
        elif l<i or abs(z)>l-i:a=1
        else:z-=1
    print('YNeos'[a::2])

import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))

def solve():
	n, k, l = mints()
	x = 0
	pz = k
	for d in mints():
		z = l - d
		if z < 0:
			print("No")
			return
		if z >= k:
			x = 0
		elif x < k:
			x = max(x + 1, k - z)
		elif x >= k:
			x = x + 1
			if x - k > z:
				print("No")
				return
		pz = max(z, k)
	print("Yes")

for i in range(mint()):
	solve()


for _ in range(int(input())):
    n, k, l = map(int, input().split());dd = list(map(int, input().split()));t,curld,di = 0,0,False
    for d in [-(2**30), *dd]:
        if d > l:break
        ld = l - d
        if d + k <= l:curld,di = ld,False;continue
        if di:
            if ld >= curld + 1:curld += 1
            else:break
        else:
            curld = min(curld - 1, ld)
            if curld == 0:di = True
    else:print('Yes');continue
    print('No')



for _ in range(int(input())):
	nkl = list(map(int,input().split()))
	n = nkl[0]
	k = nkl[1]
	l = nkl[2]
	d = list(map(int,input().split()))
	flag=1
	count=0
	leez = 0
	for i in range(n):
		if(d[i]>l):
			flag=0
			break
		else:
			if(l-d[i]>=k):
				count=0
				continue
			count+=1
			if(count==1):
				leez = l-d[i]
				continue
			leez = min(leez-1,l-d[i])
			if(leez>=0):
				continue
			if(-leez<=l-d[i]):
				continue
			else:
				flag=0
				break
	if(flag==1):
		print("Yes")
	else:
		print("No")

	




import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write('\n'.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7



for t in range(int(data())):
    n,k,l=mdata()
    d=mdata()
    flag=True
    m=k
    p=0
    for j in range(0,n):
        if l-d[j]>=k:
            m=k-1
            p=0
        else:
            if (d[j]+m>l and p==1) or d[j]>l:
                flag=False
                break
            if p==0:
                m=min(m-1,l-d[j]-1)
                if m==-1:
                    p=1
                    m=1
            else:
                m+=1
    if flag==True:
        out("Yes")
    else:
        out("No")



import sys
inpy = [int(x) for x in sys.stdin.read().split()]
t = inpy[0]
index = 1
for _ in range(t):
    n, k, l = inpy[index], inpy[index+1], inpy[index+2]
    index += 3
    d = inpy[index:index+n]
    
    index += n
    x, m = k, True
    flag = True
    for i in range(n):
        diff = l - d[i]
    
        if diff < 0:
            flag = False
            break
        if diff >= k:
            x = k
            m = True
        else:
            if m:
                x = min(x - 1, diff)
                if x ==  0:
                    m = False
            else:
                x = x + 1
                if x > diff:
                    flag = False
                    break    
    if flag :   
        print('Yes')
    else:
        print('No')





import sys
 
def minp():
	return sys.stdin.readline().strip()
 
def mint():
	return int(minp())
 
def mints():
	return map(int, minp().split())
 
def solve():
	n, k, l = mints()
	x = 0
	pz = k
	for d in mints():
		z = l - d
		if z < 0:
			print("No")
			return
		if z >= k:
			x = 0
		elif x < k:
			x = max(x + 1, k - z)
		elif x >= k:
			x = x + 1
			if x - k > z:
				print("No")
				return
		pz = max(z, k)
	print("Yes")
 
for i in range(mint()):
	solve()