#include <bits/stdc++.h>#defineREP (I,A,B) for (int i=a;i<=b;i++)#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn=2000100;Const intinf=1<< in;intS,n;intX[MAXN];intCNT[MAXN],M[MAXN];intMain () {Freopen ("In.txt","R", stdin); Freopen ("OUT.txt","W", stdout); intT;cin>>u; while(t--) {scanf ("%d%d",&s,&N); REP (i,1, N) scanf ("%d",&X[i]); MS0 (CNT); MS0 (m); intk=1; intans=0, tag=1; REP (i,1, N) {Cnt[x[i]+k*s]++; if(cnt[x[i]+k*s]==2) m[k]++,tag=0; if(i%s==0) k++; } if(tag) ans++; //REP (i,0,k) cout<<m[i]<< "";cout<<endl;REP (I,2, s) { intL=i; intk=1; BOOLtag=1; while(L-1<=N) { //cout<<l-1<< "=" <<x[l-1]<< "<<cnt[x[l-1]+ (k-1) *s]<<" "<<x[l-1]+ ( k-1) *s<<endl;cnt[x[l-1]+ (K-1) *s]++; if(cnt[x[l-1]+ (K-1) *s]==2) m[k-1]++; Cnt[x[l-1]+k*s]--; if(cnt[x[l-1]+k*s]==1) m[k]--; if(m[k-1]) tag=0; K++; L+=s; } //cout<< "i=" <<i<< "tag=" <<tag<<endl; //REP (i,0,k-1) cout<<m[i]<< "";cout<<endl; if(m[k-1]) tag=0; if(tag) ans++; } printf ("%d\n", ans); } return 0;}/** First clear a fact: N number is divided into K-s segment, the spatial complexity of k*s<=n+s. Then you can draw the window. Initial spatial complexity estimation error, direct to violence ... why am I stupid ...*/
View Code
UVA 12174 Shuffle