题目链接:http://codeforces.com/problemset/problem/367/B点击打开链接
一开始想法使用multiset坐 但是会超空间
用队列从1~p通过一个队列往后判断 如果当前与b数列相等 将即将入队的元素跟队首元素进行比较就可
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <limits>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
map<int ,int> mmap;
map<int ,int>b;
map<int ,int>a;
map<int , int >ans;
map<int ,int > :: iterator it;
int main()
{
int n;int m;int p;
scanf("%d%d%d",&n,&m,&p);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
{
int mid;
scanf("%d",&mid);
b[mid]++;
}
for(int i=1;i<=p;i++)
{
queue<int > q;
for(int j=i;j<=n;j+=p)
{
if(q.size()<m)
{
q.push(j);
mmap[a[j]]++;
}
if(q.size()==m)
{
if(mmap==b)
ans[q.front()]++;
mmap[a[q.front()]]--;
if(!mmap[a[q.front()]])
mmap.erase(a[q.front()]);
q.pop();
}
}
mmap.clear();
}
//cout <<endl;
cout << ans.size()<< endl;
for(it=ans.begin();it!=ans.end();it++)
cout << (*it).first <<" ";
}