Yesterday afternoon thought for a long time did not think out, sure enough is very weak, thinking ability is low.
Like the idea of a monotone queue, maintenance of a length of the $k+1$ slider, each time the statistics $ans$ can be
#include <cstdio> #include <algorithm>using namespace Std;int N, K, h[100003], id[100003], a[100003], cnt = 0, C [100003], st, ans = 0;inline bool cmp (int X, int Y) {return h[x] < h[y];} int main () {scanf ("%d%d\n", &n, &k), for (int i = 1; I <= n; ++i) {scanf ("%d\n", &h[i]); id[i] = i;} Id[0] = 0; H[0] = 100003;sort (id + 1, ID + n + 1, CMP); for (int i = 1; I <= n; ++i) {if (H[id[i]]! = h[id[i-1]]) ++cnt;a[id[i]] = cn t;} CNT = 0;ST = 0;for (int i = 1; I <= n; ++i) {++c[a[i]];if (c[a[i]] = = 1) {++cnt;while (cnt > k + 1) {--c[a[st]];if (c [A[st]] = = 0)--cnt;++st;}} ans = max (ans, c[a[i]);} printf ("%d\n", ans); return 0;}
No more.
"Bzoj 3048" "USACO2013 Jan" Cow lineup Slider thought