Language: C++

include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}
 
template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    vector<Monoid> data;
    int n;
    const F f;
    const Monoid M;
    SegmentTree(int x, const F f, const Monoid &M) : f(f), M(M) {
        n = 1;
        while(n<x) n <<= 1;
        data.resize(2*n,M);
    }
    void set(int k, const Monoid &p) {
        data[k+n] = p;
    }
    void build() {
        for(int k = n-1; k > 0; --k) {
            data[k] = f(data[2*k + 0], data[2*k + 1]);
        }
    }
    void update(int k, const Monoid &p) {
        k += n;
        data[k] = p;
        while (k >>= 1) {
            data[k] = f(data[k*2], data[k*2 + 1]);
        }
    }
    Monoid query(int a, int b) {
        Monoid L = M, R = M;
        for(a += n, b += n; a<b; a >>= 1, b >>= 1) {
            if(a&1) L = f(L, data[a++]);
            if(b&1) R = f(data[--b], R);
        }
        return f(L,R);
    }
    Monoid operator[](const int &k) const {
        return data[k+n];
    }
};
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> p(n), x(n);
    SegmentTree<int> segmin(n, [](int a,int b){return min(a,b);}, INT_MAX);
    SegmentTree<int> segmax(n, [](int a,int b){return max(a,b);}, INT_MIN);
    REP(i,n) {
        cin >> p[i];
        segmin.update(i,p[i]);
        segmax.update(i,p[i]);
    }
    vector<int> cnt(n);
    REP(i,n-1) {
        cnt[i+1] = cnt[i] + (p[i]>p[i+1]);
    }
    int ans = 1;
    int s = (cnt[k-1]-cnt[0]>0);
    REP(i,n-k) {
        int x = segmin.query(i,i+k+1);
        int y = segmax.query(i,i+k+1);
        if((s || cnt[i+k]-cnt[i+1]>0) && (p[i]!=x || p[i+k]!=y)) {
            if(cnt[i+k]-cnt[i+1]==0) s = 0;
            ++ ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
a.cc:16:15: error: 'function' does not name a type; did you mean 'union'?
   16 |     using F = function<Monoid(Monoid, Monoid)>;
      |               ^~~~~~~~
      |               union
a.cc:17:5: error: 'vector' does not name a type
   17 |     vector<Monoid> data;
      |     ^~~~~~
a.cc:19:11: error: 'F' does not name a type
   19 |     const F f;
      |           ^
a.cc:21:30: error: 'F' does not name a type
   21 |     SegmentTree(int x, const F f, const Monoid &M) : f(f), M(M) {
      |                              ^
a.cc: In constructor 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&)':
a.cc:21:54: error: class 'SegmentTree<Monoid>' does not have any field named 'f'
   21 |     SegmentTree(int x, const F f, const Monoid &M) : f(f), M(M) {
      |                                                      ^
a.cc:24:9: error: 'data' was not declared in this scope
   24 |         data.resize(2*n,M);
      |         ^~~~
a.cc: In member function 'void SegmentTree<Monoid>::set(int, const Monoid&)':
a.cc:27:9: error: 'data' was not declared in this scope
   27 |         data[k+n] = p;
      |         ^~~~
a.cc: In member function 'void SegmentTree<Monoid>::build()':
a.cc:31:13: error: 'data' was not declared in this scope
   31 |             data[k] = f(data[2*k + 0], data[2*k + 1]);
      |             ^~~~
a.cc:31:23: error: there are no arguments to 'f' that depend on a template parameter, so a declaration of 'f' must be available [-fpermissive]
   31 |             data[k] = f(data[2*k + 0], data[2*k + 1]);
      |                       ^
a.cc:31:23: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In member function 'void SegmentTree<Monoid>::update(int, const Monoid&)':
a.cc:36:9: error: 'data' was not declared in this scope
   36 |         data[k] = p;
      |         ^~~~
a.cc:38:23: error: there are no arguments to 'f' that depend on a template parameter, so a declaration of 'f' must be available [-fpermissive]
   38 |             data[k] = f(data[k*2], data[k*2 + 1]);
      |                       ^
a.cc: In member function 'Monoid SegmentTree<Monoid>::query(int, int)':
a.cc:44:30: error: 'data' was not declared in this scope
   44 |             if(a&1) L = f(L, data[a++]);
      |                              ^~~~
a.cc:45:27: error: 'data' was not declared in this scope
   45 |             if(b&1) R = f(data[--b], R);
      |                           ^~~~
a.cc: In member function 'Monoid SegmentTree<Monoid>::operator[](const int&) const':
a.cc:50:16: error: 'data' was not declared in this scope
   50 |         return data[k+n];
      |                ^~~~
a.cc: In function 'int main()':
a.cc:55:5: error: 'cin' was not declared in this scope
   55 |     cin.tie(0);
      |     ^~~
a.cc:56:5: error: 'ios' has not been declared
   56 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:58:5: error: 'vector' was not declared in this scope
   58 |     vector<int> p(n), x(n);
      |     ^~~~~~
a.cc:58:12: error: expected primary-expression before 'int'
   58 |     vector<int> p(n), x(n);
      |            ^~~
a.cc: In lambda function:
a.cc:59:55: error: 'min' was not declared in this scope; did you mean 'main'?
   59 |     SegmentTree<int> segmin(n, [](int a,int b){return min(a,b);}, INT_MAX);
      |                                                       ^~~
      |                                                       main
a.cc: In function 'int main()':
a.cc:59:67: error: 'INT_MAX' was not declared in this scope
   59 |     SegmentTree<int> segmin(n, [](int a,int b){return min(a,b);}, INT_MAX);
      |                                                                   ^~~~~~~
a.cc:1:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
  +++ |+#include <climits>
    1 | include <bits/stdc++.h>
a.cc: In lambda function:
a.cc:60:55: error: 'max' was not declared in this scope
   60 |     SegmentTree<int> segmax(n, [](int a,int b){return max(a,b);}, INT_MIN);
      |                                                       ^~~
a.cc: In function 'int main()':
a.cc:60:67: error: 'INT_MIN' was not declared in this scope
   60 |     SegmentTree<int> segmax(n, [](int a,int b){return max(a,b);}, INT_MIN);
      |                                                                   ^~~~~~~
a.cc:60:67: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:62:16: error: 'p' was not declared in this scope
   62 |         cin >> p[i];
      |                ^
a.cc:66:12: error: expected primary-expression before 'int'
   66 |     vector<int> cnt(n);
      |            ^~~
a.cc:68:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   68 |         cnt[i+1] = cnt[i] + (p[i]>p[i+1]);
      |         ^~~
      |         int
a.cc:68:30: error: 'p' was not declared in this scope
   68 |         cnt[i+1] = cnt[i] + (p[i]>p[i+1]);
      |                              ^
a.cc:71:14: error: 'cnt' was not declared in this scope; did you mean 'int'?
   71 |     int s = (cnt[k-1]-cnt[0]>0);
      |              ^~~
      |              int
a.cc:75:43: error: 'p' was not declared in this scope
   75 |         if((s || cnt[i+k]-cnt[i+1]>0) && (p[i]!=x || p[i+k]!=y)) {
      |                                           ^
a.cc:80:5: error: 'cout' was not declared in this scope
   80 |     cout << ans << endl;
      |     ^~~~
a.cc:80:20: error: 'endl' was not declared in this scope
   80 |     cout << ans << endl;
      |                    ^~~~
a.cc: In instantiation of 'Monoid SegmentTree<Monoid>::query(int, int) [with Monoid = int]':
a.cc:73:29:   required from here
   73 |         int x = segmin.query(i,i+k+1);
      |                 ~~~~~~~~~~~~^~~~~~~~~
a.cc:44:39: error: 'f' was not declared in this scope
   44 |             if(a&1) L = f(L, data[a++]);
      |                                       ^
a.cc:45:26: error: 'f' was not declared in this scope
   45 |             if(b&1) R = f(data[--b], R);
      |                         ~^~~~~~~~~~~~~~
a.cc:47:17: error: 'f' was not declared in this scope
   47 |         return f(L,R);
      |                ~^~~~~