Language: C++

#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX_N = 1 << 17;
int nn1, dat1[12345678]; //セグメント木を持つグローバル配列
void init1(int n_) {
	nn1 = 1; while (nn1 < n_)nn1 *= 2;
	for (int i = 0; i < 2 * nn1 - 1; i++) dat1[i] = INT_MAX;
}
void update1(int k, int a) {
	k += nn1 - 1; dat1[k] = a;
	while (k > 0) { k = (k - 1) / 2; dat1[k] = min(dat1[k * 2 + 1], dat1[k * 2 + 2]); }
}
int query1(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) { return INT_MAX; }
	if (a <= l && r <= b) { return dat1[k]; }
	else {
		int vl = query1(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query1(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}
int nn2, dat2[12345678]; //セグメント木を持つグローバル配列
void init2(int n_) {
	nn2 = 1; while (nn2 < n_)nn2 *= 2;
	for (int i = 0; i < 2 * nn1 - 1; i++) dat1[i] = 0;
}
void update2(int k, int a) {
	k += nn2 - 1; dat2[k] = a;
	while (k > 0) { k = (k - 1) / 2; dat2[k] = max(dat2[k * 2 + 1], dat2[k * 2 + 2]); }
}
int query2(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) { return 0; }
	if (a <= l && r <= b) { return dat2[k]; }
	else {
		int vl = query2(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query2(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
}
int res[12345678], mi[12345678], ma[12345678], ok[12345678];
signed main() {
	int n, k, ans = 0; cin >> n >> k; init1(n); init2(n);
	vector<int> v;
	for (int h = 0; h < n; h++) {
		cin >> res[h]; update1(h, res[h]); update2(h, res[h]);
	}
	int cnt = 1;
	for (int h = 1; h < n; h++) {
		if (res[h - 1] < res[h]) { cnt++; }
		else { cnt = 1; }
		if (cnt >= k) { ok[h - k + 1] = 1; }
	}
	for (int h = 0; h <= n - k; h++) {
		if (ok[h] == 1) { ans++; continue; }
		if (query1(h, h + k, 0, 0, nn1) == res[h]) { mi[h]++; }
		if (query2(h, h + k, 0, 0, nn2) == res[h + k - 1]) { ma[h]++; }
	}
	ans = max((long long)0, ans - 1);
	for (int h = 1; h < n; h++) {
		if (mi[h - 1] == 1 && ma[h] == 1) { ans++; }
	}
	cout << n - k + 1 - ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void init1(long long int)':
a.cc:25:57: error: 'INT_MAX' was not declared in this scope
   25 |         for (int i = 0; i < 2 * nn1 - 1; i++) dat1[i] = INT_MAX;
      |                                                         ^~~~~~~
a.cc:15:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   14 | #include<functional>
  +++ |+#include <climits>
   15 | //#include<bits/stdc++.h>
a.cc: In function 'long long int query1(long long int, long long int, long long int, long long int, long long int)':
a.cc:32:40: error: 'INT_MAX' was not declared in this scope
   32 |         if (r <= a || b <= l) { return INT_MAX; }
      |                                        ^~~~~~~
a.cc:32:40: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'