Xiao Ming Series Problems--Xiao Ming sequenceTime
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 4521
Description
We all know that Xiao Ming likes to study the problems related to the sequence, but also because of this, xiaoming almost has been playing all kinds of sequence problems. Poor Xiaoming was struggling to find new sequence problems on various websites, but finding them was a sequence that he had already studied. Xiao Ming thought that since can not find, then he invented a new sequence problem it! Xiao Ming think, think, finally came up with a new sequence problem, he was ecstatic, because he thought out, so his new sequence problem named "Xiaoming sequence."
To mention the sequence of xiaoming, the definition he gives is this:
① first defines S as an ordered sequence, s={A1, A2, A3, ..., an},n is the number of elements;
② then defines a sub sequence to be taken out of S, sub={Ai1, Ai2, Ai3, ..., Aim},m is the number of elements;
③ where sub satisfies Ai1 < Ai2 < Ai3 < ... < Aij-1 < Aij < Aij+1 < ... < Aim;
④ at the same time sub satisfies for any connected two Aij-1 and AIJ have ij-ij-1 > D (1 < J <= M, D for a given integer);
⑤ obviously satisfies such sub-subsequence there are many, and in these sub-sequence sub-sequences, the number of elements is called "xiaoming sequence" (that is, m the largest sub-subsequence).
For example: Sequence s={2,1,3,4}, where d=1;
Can get "xiaoming sequence" of the m=2. That is, sub={2,3} or {2,4} or {1,4} are all "xiaoming sequences".
When Xiao Ming invented the "xiaoming sequence" that moment, the emotion is very excited, so that the mind is messy, so he wants to ask you to help him to calculate in the given S-sequence and the whole number D, how many of the elements in the "xiaoming sequence" need?
Input
Multiple input data sets, processing to the end of the file;
The first behavior of the input two positive integers n and D; (1<=n<=10^5, 0<=d<=10^5)
The second behavior of the input n integers A1, A2, A3, ..., an, represents n elements of the s sequence. (0<=ai<=10^5)
Output
Please output the number of elements in the "xiaoming sequence" for each set of data, one row for each test data output.
Sample Input
2 01 25 13 4 5 1 25 23 4 5 1 2
Sample Output
221
#include <bits/stdc++.h>using namespace Std;const int M = 1e5 + ten, inf = 0x3f3f3f3f;int n, D; int a[m], top[m], Maxn[m];int judge (int x) {int L = 0, r = N; int ret = l; while (L <= r) {int mid = L + R >> 1; if (x > Top[mid]) {L = mid+1; ret = mid; } else R = mid-1; } return ret+1;} void Solve () {int ans = 0; for (int i = 1; I <= n; i + +) {Maxn[i] = judge (A[i]); ans = max (Maxn[i], ans); int j = i-d; if (J > 0) top[maxn[j]] = min (top[maxn[j]], a[j]); } printf ("%d\n", ans);} int main () {while (~ scanf ("%d%d", &n, &d)) {top[0] =-inf; for (int i = 1; I <= n; i + +) {scanf ("%d", &a[i]); Top[i] = iNF; } solve (); } return 0;}
I think most people who write Lis will not set an array to record the oldest sequence of Lis at the end of each value, because:
1. We generally only care about the whole LIS.
2. The LIS that usually find out the sub-sequence is immediately taken with the new Top[lis], where an array needs to exist.
And then this leads to a stalk, and I have no thought about what the local LIS is for.
In terms of this problem, the idea is actually four words:
Delay and new.
Delay d time with the metropolis.
Xiao Ming Series Problems--Xiao Ming sequence (LIS)