Language: C++

#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}


int main() {
    ll n, k;
    cin>>n>>k;
    vector<ll> p(n);
    cin>>p;
    ll sss=0;
    ll lngt = 1;
    rep(i,n-1){
        if(p[i]<p[i+1]) lngt++;
        else lngt=1;
        if(lngt>=k) sss++;
    }
    // k--;
    ll aaa;
    {
        bool l=false, h=false, s=false;
        ll lsum=0,ssum = 0;
        set<ll> se;
        fr(i,0,k){
            se.insert(p[i]);
        };
        rep(i, n) {
            auto r = i+k;
            if(r >n) break;

            ll tmpl ;
            ll tmph ;
            if(i==0){
            tmpl = *min_element(p.begin()+i, p.begin()+r) == p[i];
            tmph = *max_element(p.begin()+i, p.begin()+r) == p[r-1];
            }else{
                se.erase(se.begin());
                se.insert(p[r-1]);
                tmpl = *(se.begin()) == p[i];
                tmph = (*(se.end()-1))== p[r-1];
            }
            if (!s && l && tmph) lsum++;
            bool tmps = false;
            // cout<<i<<endl;
            if (i==0) {
                s = true;
                tmps = true;
                fr(j,i,r-1) if(p[j]>p[j+1]) {
                    s = false;
                    tmps=false;
                }
            }else if (h && tmph && s) tmps=true;
            if(tmps) ssum++;

            l=tmpl;
            h=tmph;
            s=tmps;
        }
        aaa = lsum;
        // pr(ssum);
        // pr(lsum);
    }
    // pr(aaa);
    // pr(sss);
    pr(n-k+1  - max((ll)0,(sss - 1)) -aaa);
    // pr(sss);
    // pr(aaa);

}

Compiler output:
a.cc: In function 'int main()':
a.cc:133:35: error: no match for 'operator-' (operand types are 'std::set<long long int>::iterator' {aka 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator'} and 'int')
  133 |                 tmph = (*(se.end()-1))== p[r-1];
      |                           ~~~~~~~~^~
      |                                 |  |
      |                                 |  int
      |                                 std::set<long long int>::iterator {aka std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator}
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:133:36: note:   'std::set<long long int>::iterator' {aka 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator'} is not derived from 'const std::reverse_iterator<_Iterator>'
  133 |                 tmph = (*(se.end()-1))== p[r-1];
      |                                    ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:133:36: note:   'std::set<long long int>::iterator' {aka 'std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator'} is not derived from 'const std::move_iterator<_IteratorL>'
  133 |                 tmph = (*(se.end()-1))== p[r-1];
      |                                    ^