Problem:


Score : 700 points

Problem Statement

Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).

Now, he will perform the following operation exactly once:

Choose K consecutive elements in P and sort them in ascending order.

Find the number of permutations that can be produced as P after the operation.

Constraints

2 \leq N \leq 200000

2 \leq K \leq N

0 \leq P_i \leq N-1

P_0,P_1,\cdots,P_{N-1} are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_0 P_1 \cdots P_{N-1}

Output

Print the number of permutations that can be produced as P after the operation.

Sample Input 1

5 3
0 2 1 4 3

Sample Output 1

2

Two permutations can be produced as P after the operation: (0,1,2,4,3) and (0,2,1,3,4).

Sample Input 2

4 4
0 1 2 3

Sample Output 2

1

Sample Input 3

10 4
2 0 1 3 7 5 4 6 8 9

Sample Output 3

6



Sample input:
5 3
0 2 1 4 3


Sample output:
2

Submission status: Accepted

Solution code:
import subprocess
import gzip, base64, os
import stat

gz = b'H4sIAPH7hl0C/719DWBTRbbwTfoX/pqgiBVQilYoIqWBAq1/pNDAjaSAtBRUMJQ0pcW2qc0NPy4obluXayyyPp/L83N9vH27rs/9Y13XRVahFaH4D7IiiEJhUW+o/KgIVcR858zMTefe3FtB970onZxzz8yZc+bMmTMzNzP3u71TrRaLoH6swi0CQn8e7CKwi+HX+OMkgMsXesHfocIQIRXgFI7OJbg0aRcrWk1tjC4J/iXDv3wrhfOtLk06hNGpqYVLUwT+49KkaxYImlQQMuP5sK77GH7fgoWa1JFM8blp2nxWlq+L5eti9GoqWAVNqsqXzP6VMnwpk0tNixhdEUePn1kfSxX4XZxLYXGuS5M2MbomXb7bIF+qcOEfB0tnM35meslm9VdTtR3G1FQvmpA3pqZidE11XXj56OX5E0ZPyMsJBXPGkjo5GO20GXM0esxgdR7AbACfp6c9+NSva99vSNq49sDh/9j94cZ+/VbjswKWD5ukuc5RlTysl9Ui5AmroWh8dhP8K4R/z3047r3eD6zz/dL/8va1tbGda5r9A/9RsqHx4dtdn4/+3HdXeubS3Gz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hq46WXhzpD4WJ5EKcw0XeTaqvgeG1vQnVNLxYWEOVU3BBVySTazgTi+cu+zRQUQ93F2vr4HQKTDvGF4Zqy6ZXczIcu2mT3PepRSVc2al73OMNrXppEu461bdy932iiWxM7hVObFLTO4ATuOE7J9DmNTW++I3JP+yGZG3J5JJUAwESb1DW1ajHK7Rn+siPJnzhUKAi8eZkXQ0aAoGECvR0v7E2O73fVVdAD3d46zu96TXdRuadcIGtoZswuoXboCcZ3LGrpzK4tllvGCCe6hETLq1OtDdy13EimruFW19+RSjoq4KRFpRHL9c17HPo7VgI9S+8LVzvt9jdvHpr0d52rZcu8Z5ovYiLQiHOIuJXpSc0xgXdn+xycXcAJ976bOhFEq6ATixEe022USnaO+i1JRjeXG9y4bvO9ZKrkg0cxA+7+FzX9QPBSr05xa+H10pAxvIfdvm4jif5jVWCCV3w3d8Gw/JEflgmjbnUrLub3Ktu1J7cxew6VZCX5IxuVE80m3/BzeEGA6OBdGyES3B0muu64Rm7PptUbgKaPcy6EwcX7mJ1gwiHXo1uUAn9vfGJply/orvlnXmJ14/r447qOoH6tf8PzdGB5A6MAAA='
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)


# compiled by pythran
'''
#pythran export main2()
import numpy as np
i8 = np.int64
i4 = np.int32


def maxpush(val, que, sz):
    i = sz
    while i > 0:
        parent = (i - 1) // 2
        if que[parent] < val:
            que[i] = que[parent]
            i = parent
        else:
            que[i] = val
            break
    else:
        que[0] = val


def maxpop(que, sz):
    if sz == 0:
        return -1
    ret = que[0]
    sz -= 1
    val = que[sz]
    i = 0
    while True:
        child = 2 * i + 1
        if child >= sz:
            que[i] = val
            break
        if que[child] > que[child + 1]:
            if que[child] > val:
                que[i] = que[child]
                i = child
            else:
                que[i] = val
                break
        else:
            if que[child + 1] > val:
                que[i] = que[child + 1]
                i = child + 1
            else:
                que[i] = val
                break
    return ret


def minpush(val, que, sz):
    i = sz
    while i > 0:
        parent = (i - 1) // 2
        if que[parent] > val:
            que[i] = que[parent]
            i = parent
        else:
            que[i] = val
            break
    else:
        que[0] = val


def minpop(que, sz):
    if sz == 0:
        return -1
    ret = que[0]
    sz -= 1
    val = que[sz]
    i = 0
    while True:
        child = 2 * i + 1
        if child >= sz:
            que[i] = val
            break
        if que[child] < que[child + 1]:
            if que[child] < val:
                que[i] = que[child]
                i = child
            else:
                que[i] = val
                break
        else:
            if que[child + 1] < val:
                que[i] = que[child + 1]
                i = child + 1
            else:
                que[i] = val
                break
    return ret



def solve(P, K):
    count = 0
    n = P.shape[0]
    p_ind = np.empty(n, i8)
    for i in range(n):
        p_ind[P[i]] = i
    maxque = np.empty(n, i8)
    maxsz = 0
    minque = np.empty(n, i8)
    minsz = 0
    for i in range(K):
        maxpush(P[i], maxque, maxsz)
        maxsz += 1
        minpush(P[i], minque, minsz)
        minsz += 1
    for i in range(n - K):
        maxpush(P[i + K], maxque, maxsz)
        maxsz += 1
        minpush(P[i + K], minque, minsz)
        minsz += 1
        while p_ind[maxque[0]] < i:
            maxpop(maxque, maxsz)
            maxsz -= 1
        while p_ind[minque[0]] < i:
            minpop(minque, minsz)
            minsz -= 1
        # 最初の数字が最小で後側の数字が最大であれば結果は同じ
        if minque[0] == P[i] and maxque[0] == P[i + K]:
            count += 1

    # K個昇順の場合は、元の数列と同じ
    m = 0
    k_conti = 0
    for i in range(n - 1):
        if P[i] < P[i + 1]:
            m += 1
        else:
            if m >= K - 1:
                k_conti += 1
            m = 0
    else:
        if m >= K - 1:
            k_conti += 1

    return n - K + 1 - count - max(k_conti - 1, 0)

def main2():
    stdin = open('/dev/stdin')
    N, K = map(int, stdin.readline().split())
    P = np.empty(N, i8)
    for i, c in enumerate(stdin.readline().split()):
        P[i] = int(c)
    ans = solve(P, K)
    print(ans)
'''