First, preprocess the number of front s that end with each count to make a 1~s arrangement.
You can use the CNT array to record the number of occurrences of each number and how many different numbers appear with a variable record.
Then enumerate each possible case, that is, the position where the first song appears, taking into account the incomplete sequence.
Code is not long, but that OK array to write a bit of egg ache, because to consider the existence of incomplete sequence, changed for a long time to change.
1#include <cstdio>2#include <cstring>3#include <cassert>4 5 Const intMAXN =100000+Ten;6 intA[MAXN], S, N, CNT[MAXN *2];7 BOOLOK[MAXN *3];8 9InlineBOOL inch(intx) {returnX >=1&& x <=N;}Ten One intMain () A { - //freopen ("In.txt", "R", stdin); - the intT scanf"%d", &T); - while(t--) - { -scanf"%d%d", &s, &n); +Memset (A,-1,sizeof(a)); - for(inti =1; I <= N; i++) scanf ("%d", &a[i]); +memset (CNT,0,sizeof(CNT)); A //memset (OK, false, sizeof (OK)); at inttot =s; - for(inti =1; I < n + S; i++) - { - if(inch(i-s)) {cnt[a[i-s]]--;if(!cnt[a[i-s]]) tot--; } - Elsetot--; - if(inch(i)) {cnt[a[i]]++;if(Cnt[a[i]] = =1) tot++; } in Elsetot++; -Ok[i] = tot = =s; to } + - intAns =0; the for(intx =1-S; X <=0; X + +) * { $ BOOLFlag =true;Panax Notoginseng for(inti = x; i < n+s; i + =s) - { the if(I <=0)Continue; + if(!ok[i]) {flag =false; Break; } A } the if(flag) +ans++; - } $ $printf"%d\n", ans); - } - the return 0; -}
code June
UVa 12174 (sliding window) Shuffle