（中文音译叫霍尔定理）

_(:зゝ∠)_

# 例题

「2017 山东一轮集训 Day2」Pair LOJ – 6062

#include <bits/stdc++.h>

#define NS (150005)
#define LS(a) ((a) << 1)
#define RS(a) ((a) << 1 | 1)

using namespace std;

template<typename _Tp> inline void IN(_Tp& dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
if (flag) dig = -dig;
}

int n, m, h, A[NS], B[NS], ans;

struct N {int mn, tag;} e[NS << 2];

void pup(int a) { e[a].mn = min(e[LS(a)].mn, e[RS(a)].mn); }

void pdown(int a)
{
if (!e[a].tag) return;
int l = LS(a), r = RS(a);
e[l].mn += e[a].tag, e[l].tag += e[a].tag;
e[r].mn += e[a].tag, e[r].tag += e[a].tag;
e[a].tag = 0;
}

void build(int l, int r, int a)
{
if (l == r) { e[a].mn = -l; return; }
int mid = (l + r) >> 1;
build(l, mid, LS(a)), build(mid + 1, r, RS(a)), pup(a);
}

void add(int l, int r, int d, int L, int R, int a)
{
if (l <= L && R <= r) { e[a].mn += d, e[a].tag += d; return; }
pdown(a);
int Mid = (L + R) >> 1;
if (l <= Mid) add(l, r, d, L, Mid, LS(a));
if (r > Mid) add(l, r, d, Mid + 1, R, RS(a));
pup(a);
}

int main(int argc, char const* argv[])
{
IN(n), IN(m), IN(h);
for (int i = 1; i <= m; i += 1) IN(B[i]);
for (int i = 1; i <= n; i += 1) IN(A[i]);
sort(B + 1, B + 1 + m), build(1, m, 1);
for (int i = 1; i < m; i += 1)
{
int j = lower_bound(B + 1, B + 1 + m, h - A[i]) - B;
if (j <= m) add(j, m, 1, 1, m, 1);
}
for (int i = m; i <= n; i += 1)
{
int j = lower_bound(B + 1, B + 1 + m, h - A[i]) - B;
if (j <= m) add(j, m, 1, 1, m, 1);
if (e[1].mn >= 0) ans++;
j = lower_bound(B + 1, B + 1 + m, h - A[i - m + 1]) - B;
if (j <= m) add(j, m, -1, 1, m, 1);
}
printf("%d\n", ans);
return 0;
}


#### Remmina

No puzzle that couldn't be solved.

%%%

%%%Tql

前排捕捉