Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define repeat(n) for(register int _______ = (n); _______ > 0; --_______)
#define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
#define iloop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i < __r; ++i)
#define rloop(i, r, l) for(register auto i = (r), __l = decltype(i)(l); i >= __l; --i)

using LL = long long;

template<typename Container>
inline
int ssize(Container& x)
{ return x.size(); }

#ifdef CAI_WEI_HAN
#include "my_print.h"
#include "LOG.h"
#else
#define LOG(...)
#endif

class Monotone_Queue_Min
{
public:
	void push(int i, int x)
	{
		while(begin != end && X[end - 1] >= x)
			end--;
		
		I[end] = i;
		X[end] = x;
		end++;
	}
	
	void pop_until(int i)
	{
		while(begin != end && I[begin] < i)
			begin++;
	}
	
	int min()
	{ return X[begin]; }
	
	int size()
	{ return end - begin; }
	
private:
	int I[200005];
	int X[200005];
	int begin = 0, end = 0;
};

class Monotone_Queue_Max
{
public:
	void push(int i, int x)
	{
		while(begin != end && X[end - 1] <= x)
			end--;
		
		I[end] = i;
		X[end] = x;
		end++;
	}
	
	void pop_until(int i)
	{
		while(begin != end && I[begin] < i)
			begin++;
	}
	
	int max()
	{ return X[begin]; }
	
private:
	int I[200005];
	int X[200005];
	int begin = 0, end = 0;
};

signed main()
{
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
	#define cout cerr
#else
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	constexpr char endl = '\n';
#endif
	
	int n, k;
	cin >> n >> k;
	
	static int a[200005];
	loop(i, 1, n)
		cin >> a[i];
	
	static Monotone_Queue_Min mq1;
	static Monotone_Queue_Max mq2;
	int ans1 = 1;
	loop(i, 1, n) {
		if(i > k && (a[i-k] != mq1.min() || a[i] < mq2.max()))
			LOG(i), ans1++;
		
		mq1.push(i, a[i]);
		mq1.pop_until(i-k+1);
		mq2.push(i, a[i]);
		mq2.pop_until(i-k+1);
	}
	
	int ans2 = 0;
	int j = 1;
	loop(i, 2, n) {
		if(a[i] < a[i-1]) {
			if(i-j >= k)
				ans2++;
			
			j = i;
		}
	}
	if(n-j >= k)
		ans2++;
	
	cout << ans1 - ans2;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:101:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  101 |         loop(i, 1, n)
      |              ^
a.cc:9:41: note: in definition of macro 'loop'
    9 | #define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
      |                                         ^
a.cc:9:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 | #define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
      |                                                  ^~~
a.cc:101:9: note: in expansion of macro 'loop'
  101 |         loop(i, 1, n)
      |         ^~~~
a.cc:107:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  107 |         loop(i, 1, n) {
      |              ^
a.cc:9:41: note: in definition of macro 'loop'
    9 | #define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
      |                                         ^
a.cc:9:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 | #define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
      |                                                  ^~~
a.cc:107:9: note: in expansion of macro 'loop'
  107 |         loop(i, 1, n) {
      |         ^~~~
a.cc:109:31: error: expected primary-expression before ',' token
  109 |                         LOG(i), ans1++;
      |                               ^
a.cc:119:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  119 |         loop(i, 2, n) {
      |              ^
a.cc:9:41: note: in definition of macro 'loop'
    9 | #define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
      |                                         ^
a.cc:9:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    9 | #define loop(i, l, r) for(register auto i = (l), __r = decltype(i)(r); i <= __r; ++i)
      |                                                  ^~~
a.cc:119:9: note: in expansion of macro 'loop'
  119 |         loop(i, 2, n) {
      |         ^~~~