Title Description
The length of a given number of columns and length of a number of columns , find the number of length can be continuous with the sub-series match.
Two columns can be matched, and if there is a scheme, the number of columns in the two may be paired off, the two numbers can be paired if and only if they are not less than if only .
Input Format
The first row of three numbers .
The second row has numbers .
The third row has numbers .
Output Format
A digital output, the number of length can be continuous with the sub-series match.
Sample
Sample input 1
5 2 10
5 3
1 8 5 5 7
Sample output 1
2
Sample input 2
2 2 6
2 3
3 4
Sample output 2
1
Sample input 3
4 2 10
5 5
9 3 8 9
Sample output 3
1
Data range and tips
For data ;
for data ;
for data ;
for data .
SOLUTION:
A formula can be introduced by Hall Theorem
An interval of a pair
With the sum i represents the number of a connection point of the bi
If for each sum i satisfies sum i> = i can be a perfect match
CODE:
#include <bits/stdc++.h> #define REP(i, a, b) for (int i = a; i <= b; ++i) typedef long long ll; using namespace std; void File() { freopen("loj6062.in", "r", stdin); freopen("loj6062.out", "w", stdout); } const int maxn = 1.5e5 + 10; int n, m, h, a[maxn], b[maxn], ans; struct Segment_Tree { #define mid ((l + r) >> 1) #define lc rt << 1 #define rc rt << 1 | 1 #define lson lc, l, mid #define rson rc, mid + 1, r int Min[maxn << 2], tag[maxn << 2]; void pushdown(int rt) { Min[lc] += tag[rt]; tag[lc] += tag[rt]; Min[rc] += tag[rt]; tag[rc] += tag[rt]; tag[rt] = 0; } void build(int rt, int l, int r) { if (l == r) Min[rt] = -l; else { build(lson); build(rson); Min[rt] = min(Min[lc], Min[rc]); } } void modify(int rt, int l, int r, int L, int R, int x) { if (L > R) return; if (L <= l && r <= R) { Min[rt] += x; tag[rt] += x; } else { if (tag[rt]) pushdown(rt); if (L <= mid) modify(lson, L, R, x); if (R >= mid + 1) modify(rson, L, R, x); Min[rt] = min(Min[lc], Min[rc]); } } } T; void init() { scanf("%d%d%d", &n, &m, &h); REP(i, 1, m) scanf("%d", &b[i]); sort(b + 1, b + m + 1); REP(i, 1, n) { scanf("%d", &a[i]); a[i] = lower_bound(b + 1, b + m + 1, h - a[i]) - b; } T.build(1, 1, m); REP(i, 1, m - 1) T.modify(1, 1, m, a[i], m, 1); } int main() { // File(); init(); REP(i, m, n) { T.modify(1, 1, m, a[i], m, 1); ans += (T.Min[1] >= 0); T.modify(1, 1, m, a[i - m + 1], m, -1); } printf("%d\n", ans); return 0; }