Language: C++

//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> P(N);
    vector<bool> same(N,false);

    REP(i,N){
        cin>>P[i];   
    }
    ll cnt=1;
    ll ans=0;

    

    REP(i,N-1){
        if(P[i+1]>P[i]) cnt++;
        else cnt=1;

        if(cnt>=K){
            same[i+1]=true;
            ans=1;
        }
    }

    vector<ll> dp(N+1,0);
    
    deque<ll> deq_max,deq_min;
    if(same[K-1]) dp[K]=0;
    else dp[K]=1;

    deq_max.push_back(-INF);
    deq_min.push_back(INF);
    
    REP(i,K){
        ll idx=deq_min.back();
        while(P[idx]>P[i]){
            deq_min.pop();
            idx=deq_min.back();
        }
        deq_min.back(i);
        
        idx=deq_max.back();
        while(P[idx]<P[i]){
            deq_max.pop();
            idx=deq_max.back();
        }
        deq_max.back(i);
        
    }

    REP2(i,K,N){
        dp[i+1]=dp[i];
        ll tmp1,tmp2;

        tmp2=deq_min.front();
        ll idx=deq_min.back();
        while(P[idx]>P[i]){
            deq_min.pop();
            idx=deq_min.back();
        }
        
        deq_min.back(i);
        if(deq_min.front()==i-K) deq_min.pop();
        
        idx=deq_max.back();
        while(P[idx]<P[i]){
            deq_max.pop();
            idx=deq_max.back();
        }
        deq_max.back(i);
        if(deq_max.front()==i-K) deq_max.pop();
        tmp1=deq_max.front();
        if(!same[i]&&(P[i]!=tmp1||P[i-K]>tmp2)){
            dp[i+1]++;
        }
    }
    ans+=dp[N];
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:21: error: 'class std::deque<long long int>' has no member named 'pop'
   70 |             deq_min.pop();
      |                     ^~~
a.cc:73:21: error: no matching function for call to 'std::deque<long long int>::back(ll&)'
   73 |         deq_min.back(i);
      |         ~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:139,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_deque.h:1468:7: note: candidate: 'std::deque<_Tp, _Alloc>::reference std::deque<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]'
 1468 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_deque.h:1482:7: note: candidate: 'std::deque<_Tp, _Alloc>::const_reference std::deque<_Tp, _Alloc>::back() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&]'
 1482 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1482:7: note:   candidate expects 0 arguments, 1 provided
a.cc:77:21: error: 'class std::deque<long long int>' has no member named 'pop'
   77 |             deq_max.pop();
      |                     ^~~
a.cc:80:21: error: no matching function for call to 'std::deque<long long int>::back(ll&)'
   80 |         deq_max.back(i);
      |         ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note: candidate: 'std::deque<_Tp, _Alloc>::reference std::deque<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]'
 1468 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_deque.h:1482:7: note: candidate: 'std::deque<_Tp, _Alloc>::const_reference std::deque<_Tp, _Alloc>::back() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&]'
 1482 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1482:7: note:   candidate expects 0 arguments, 1 provided
a.cc:91:21: error: 'class std::deque<long long int>' has no member named 'pop'
   91 |             deq_min.pop();
      |                     ^~~
a.cc:95:21: error: no matching function for call to 'std::deque<long long int>::back(ll&)'
   95 |         deq_min.back(i);
      |         ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note: candidate: 'std::deque<_Tp, _Alloc>::reference std::deque<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]'
 1468 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_deque.h:1482:7: note: candidate: 'std::deque<_Tp, _Alloc>::const_reference std::deque<_Tp, _Alloc>::back() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&]'
 1482 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1482:7: note:   candidate expects 0 arguments, 1 provided
a.cc:96:42: error: 'class std::deque<long long int>' has no member named 'pop'
   96 |         if(deq_min.front()==i-K) deq_min.pop();
      |                                          ^~~
a.cc:100:21: error: 'class std::deque<long long int>' has no member named 'pop'
  100 |             deq_max.pop();
      |                     ^~~
a.cc:103:21: error: no matching function for call to 'std::deque<long long int>::back(ll&)'
  103 |         deq_max.back(i);
      |         ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note: candidate: 'std::deque<_Tp, _Alloc>::reference std::deque<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]'
 1468 |       back() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1468:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_deque.h:1482:7: note: candidate: 'std::deque<_Tp, _Alloc>::const_reference std::deque<_Tp, _Alloc>::back() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; const_reference = const long long int&]'
 1482 |       back() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_deque.h:1482:7: note:   candidate expects 0 arguments, 1 provided
a.cc:104:42: error: 'class std::deque<long long int>' has no member named 'pop'
  104 |         if(deq_max.front()==i-K) deq_max.pop();
      |                                          ^~~