Language: C++

//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//一点更新区間min
template <class T>
class SegmentTree
{
private:
    int n;
    const T unit = (T)1e9;
    vector<T> node;

public:
    SegmentTree(int n_)
    {
        this->n = 1;
        while (this->n < n_)
        {
            this->n *= 2;
        }
        this->node.resize(2 * n - 1, this->unit);
    }

    SegmentTree(vector<T> v)
    {
        int n_ = v.size();
        this->n = 1;
        while (this->n < n_)
        {
            this->n *= 2;
        }
        node.resize(2 * this->n - 1, this->unit);
        for (int i = 0; i < this->n; i++)
        {
            this->node[this->n - 1 + i] = v[i];
        }
        for (int i = this->n - 2; i >= 0; i--)
        {
            this->node[i] = min(this->node[i * 2 + 1], this->node[i * 2 + 2]);
        }
    }

    void update(int idx, T val)
    {
        idx += this->n - 1;
        this->node[idx] = val;
        while (idx)
        {
            idx = (idx - 1) / 2;
            this->node[idx] = min(this->node[2 * idx + 1], this->node[2 * idx + 2]);
        }
    }

    T getmin(int a, int b, int now = 0, int l = 0, int r = -1)
    {
        if (r < 0)
        {
            r = this->n;
        }
        if (r <= a || b <= l)
        {
            return this->unit;
        }
        if (a <= l && r <= b)
        {
            return this->node[now];
        }
        T lVal = getmin(a, b, 2 * now + 1, l, (l + r) / 2);
        T rVal = getmin(a, b, 2 * now + 2, (l + r) / 2, r);
        return min(lVal, rVal);
    }
};

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, k;
    cin >> n >> k;
    akari<int> as(n), bs(n), ls(n), rs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
        bs[i] = -as[i];
    }
    for (int i = 1; i < n; i++)
    {
        if (as[i] > as[i - 1])
        {
            ls[i] = ls[i - 1];
        }
        else
        {
            ls[i] = i;
        }
    }
    rs.back() = n - 1;
    for (int i = n - 2; i >= 0; i--)
    {
        if (as[i] < as[i + 1])
        {
            rs[i] = rs[i + 1];
        }
        else
        {
            rs[i] = i;
        }
    }
    int ans = !(ls[k - 1] == 0 && k - 1 <= rs[0]), all = 1 - ans;
    SegmentTree<i64> seg(as), seg2(bs);
    for (int l = 1; l + k - 1 < n; l++)
    {
        //print(ans, all);
        int r = l + k - 1;
        if (ls[r] <= l && r <= rs[l])
        {
            all = 1;
        }
        else if (seg.getmin(l - 1, r + 1) != as[l - 1] || seg2.getmin(l - 1, r + 1) != bs[r])
        {
            ans++;
        }
    }
    ans += all;
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:143:28: error: no matching function for call to 'SegmentTree<long int>::SegmentTree(akari<int>&)'
  143 |     SegmentTree<i64> seg(as), seg2(bs);
      |                            ^
a.cc:46:5: note: candidate: 'SegmentTree<T>::SegmentTree(std::vector<_Tp>) [with T = long int]'
   46 |     SegmentTree(vector<T> v)
      |     ^~~~~~~~~~~
a.cc:46:27: note:   no known conversion for argument 1 from 'vector<int,allocator<int>>' to 'vector<long int,allocator<long int>>'
   46 |     SegmentTree(vector<T> v)
      |                 ~~~~~~~~~~^
a.cc:36:5: note: candidate: 'SegmentTree<T>::SegmentTree(int) [with T = long int]'
   36 |     SegmentTree(int n_)
      |     ^~~~~~~~~~~
a.cc:36:21: note:   no known conversion for argument 1 from 'akari<int>' {aka 'std::vector<int>'} to 'int'
   36 |     SegmentTree(int n_)
      |                 ~~~~^~
a.cc:28:7: note: candidate: 'SegmentTree<long int>::SegmentTree(const SegmentTree<long int>&)'
   28 | class SegmentTree
      |       ^~~~~~~~~~~
a.cc:28:7: note:   no known conversion for argument 1 from 'akari<int>' {aka 'std::vector<int>'} to 'const SegmentTree<long int>&'
a.cc:28:7: note: candidate: 'SegmentTree<long int>::SegmentTree(SegmentTree<long int>&&)'
a.cc:28:7: note:   no known conversion for argument 1 from 'akari<int>' {aka 'std::vector<int>'} to 'SegmentTree<long int>&&'
a.cc:143:38: error: no matching function for call to 'SegmentTree<long int>::SegmentTree(akari<int>&)'
  143 |     SegmentTree<i64> seg(as), seg2(bs);
      |                                      ^
a.cc:46:5: note: candidate: 'SegmentTree<T>::SegmentTree(std::vector<_Tp>) [with T = long int]'
   46 |     SegmentTree(vector<T> v)
      |     ^~~~~~~~~~~
a.cc:46:27: note:   no known conversion for argument 1 from 'vector<int,allocator<int>>' to 'vector<long int,allocator<long int>>'
   46 |     SegmentTree(vector<T> v)
      |                 ~~~~~~~~~~^
a.cc:36:5: note: candidate: 'SegmentTree<T>::SegmentTree(int) [with T = long int]'
   36 |     SegmentTree(int n_)
      |     ^~~~~~~~~~~
a.cc:36:21: note:   no known conversion for argument 1 from 'akari<int>' {aka 'std::vector<int>'} to 'int'
   36 |     SegmentTree(int n_)
      |                 ~~~~^~
a.cc:28:7: note: candidate: 'SegmentTree<long int>::SegmentTree(const SegmentTree<long int>&)'
   28 | class SegmentTree
      |       ^~~~~~~~~~~
a.cc:28:7: note:   no known conversion for argument 1 from 'akari<int>' {aka 'std::vector<int>'} to 'const SegmentTree<long int>&'
a.cc:28:7: note: candidate: 'SegmentTree<long int>::SegmentTree(SegmentTree<long int>&&)'
a.cc:28:7: note:   no known conversion for argument 1 from 'akari<int>' {aka 'std::vector<int>'} to 'SegmentTree<long int>&&'