//第一题手串 每种颜色分开判断
void work()
{
int ans = 0,i,j,k,flag;
for(i=0;i<=c;++i)
{
flag=0;
if(a[i].size()<1) continue;
for(j=1;j<a[i].size();++j)
if(a[i][j]-a[i][j-1]<m)
{
flag=1;
break;
}
if(a[i][0]+n-a[i].back()<m) flag=1;
ans+=flag;
}
printf("%d\n",ans);
}
//第二题查询区间中K出现的次数,莫队算法模板题,题目保证区间不包含,复杂度会降到nlogn
map<LL,LL> s;
struct Quary
{
int l,r,id,k,block;
Quary(){}
Quary(int l,int r,int k,int i):l(l),r(r),k(k),id(i){
block = l/len;
}
} Q[N];
bool cmp(Quary a,Quary b){
return a.block<b.block||a.block==b.l/len&&a.r<b.r;
}
void insert(LL x){
if(s[x])
s[x]++;
else
s[x]=1;
}
void erase(LL x){
s[x]--;
}
void work()
{
int i,j,k,l,r;
len = sqrt(n);
scanf("%d",&m);
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&l,&r,&k);
Q[i]=Quary(l,r,k,i);
}
sort(Q+1,Q+1+m,cmp);
l=1; r=1;
s[a[1]]=1;
for(i=1;i<=m;i++)
{
Quary &qi = Q[i];
while(l>qi.l) insert(a[--l]);
while(r<qi.r) insert(a[++r]);
while(l<qi.l) erase(a[l++]);
while(r>qi.r) erase(a[r--]);
anss[qi.id]=s[qi.k];
}
for(i=1;i<=m;i++)
cout << anss[i] <<endl;
}
//附加题 暴力枚举
int check(vector<int> a)
{
int ans=1,i,j,k,len=a.size();
vector<int> b(a);
for(i=0;i<len;++i)
{
for(j=0;j<=i-1;++j)
b[j]=a[i]-a[j]-i+j;
for(j=i+1;j<len;++j)
b[j]=a[j]-a[i]-j+i;
b[i]=0;
sort(b.begin(),b.end());
for(j=1;j<len;++j)
b[j]+=b[j-1];
int temp = upper_bound(b.begin(),b.end(),m) - b.begin();
if(temp > ans) ans = temp;
}
return ans;
}
void work()
{
int i,j,ans=0;
for(i=0;i<26;++i)
{
int temp=0;
if (a[i].size()) temp = check(a[i]);
//printf("%d\n",temp);
if(ans < temp) ans = temp;
}
printf("%d\n",ans);
}
#字节跳动#