Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ nq ≥ 1), such that sequence b can be obtained from sequence aq, aq + p, aq + 2p, ..., aq + (m - 1)p by rearranging elements.

Sereja needs to rush to the gym, so he asked to find all the described positions of q.

Input

The first line contains three integers n, m and p (1 ≤ n, m ≤ 2·105, 1 ≤ p ≤ 2·105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109).

Output

In the first line print the number of valid qs. In the second line, print the valid values in the increasing order.

Example

Input
5 3 1
1 2 3 2 1
1 2 3
Output
2
1 3
Input
6 3 2
1 3 2 2 3 1
1 2 3
Output
2
1 2 暴力肯定超时,总算写出来了,想到了只需要满足当判断了m个元素满足后,删除最初的那个元素以及标记,然后接着往下判断,但是写的很麻烦,后来用优先队列,但是又出了小问题(代码中有表示),很小的问题,以至于我烦的找不到。 代码:
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
struct que
{
int id,num;
friend bool operator<(que a,que b)
{
return a.id>b.id;
}
}t;
int n,m,p,a[],b[],k=,c,ans[];
int main()
{
map<int,int> mark;
scanf("%d%d%d",&n,&m,&p);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<m;i++)
{
scanf("%d",&b[i]);
mark[b[i]]++;
}
for(int i=;i<p;i++)
{
map<int,int>check;
priority_queue <que> q;
for(int j=i;j<n;j+=p)
{
//cout<<q.size()<<endl;
if(mark[a[j]]==)
{
while(!q.empty()){check[a[q.top().num]]--;q.pop();}///check的下标应该是a数组的元素 而不是a的下标
continue;
}
if(check[a[j]]<mark[a[j]])
{
check[a[j]]++;
if(q.empty())
{
t.id=,t.num=j;
q.push(t);
}
else
{
t.id=q.top().id+q.size();
t.num=j;
q.push(t);
}
}
else
{
while(!q.empty()&&a[q.top().num]!=a[j])///判断 对应位置的元素是否相等,而我当时判断了下标,傻逼吧,下标怎么可能相等,热傻了吧
{
check[a[q.top().num]]--;
q.pop();
}
t.id=q.top().id+q.size();
t.num=j;
q.push(t);
q.pop();
}
if(q.size()==m)
{
//cout<<q.top().num<<endl;
ans[k++]=q.top().num+;
check[a[q.top().num]]--;
q.pop();
//cout<<q.top().num<<endl;
}
}
}
printf("%d\n",k);
sort(ans,ans+k);
for(int i=;i<k;i++)
printf("%d ",ans[i]);
}

Sereja ans Anagrams 优先队列控制的更多相关文章

  1. Codeforces Round #215 (Div. 1) B. Sereja ans Anagrams 匹配

    B. Sereja ans Anagrams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  2. Sereja ans Anagrams

    Codeforces Round #215 (Div. 1) B:http://codeforces.com/problemset/problem/367/B 题意:给你两个序列a,b,然后给你一个数 ...

  3. Codeforces Round #215 (Div. 2) D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D 题意:有a.b两个数组,a数组有n个数,b数组有m个数,现在给出一个p,要你找出所有的位置q,使得位置q  q+ ...

  4. cf D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D #include <cstdio> #include <cstring> #includ ...

  5. Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)

    题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各 ...

  6. [ An Ac a Day ^_^ ] CodeForces 426C Sereja and Swaps 优先队列

    题意: 给你一个有n个数的序列 取一个区间 这个区间内的数可以与区间外的值交换k次 问这样的区间最大值是多少 思路: 看数据是200 时间复杂度O(n*n) 应该可以暴力 顺便学习一下优先队列 枚举区 ...

  7. Codeforces Round #215 (Div. 2) D题(离散化+hash)

    D. Sereja ans Anagrams time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces 367

    A. Sereja and Algorithm 水题不解释. B. Sereja ans Anagrams 模p同余的为一组,随便搞. C. Sereja and the Arrangement of ...

  9. Codeforces Round #215 (Div. 1)

    A Sereja and Algorithm 题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体. 分析: 分析每一段x,y,z数目是否满足构成循环体,当 ...

随机推荐

  1. CMake Error: CMake was unable to find a build program corresponding to "Ninja".

    系统环境: $ lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:g ...

  2. Codeforces 847B - Preparing for Merge Sort

    847B - Preparing for Merge Sort 思路:前面的排序的最后一个一定大于后面的排序的最后一个.所以判断要不要开始新的排序只要拿当前值和上一个排序最后一个比较就可以了. 代码: ...

  3. R—读取数据(导入csv,txt,excel文件)

    导入CSV.TXT文件 read.table函数:read.table函数以数据框的格式读入数据,所以适合读取混合模式的数据,但是要求每列的数据数据类型相同. read.table读取数据非常方便,通 ...

  4. 雷林鹏分享:C# 运算符重载

    C# 运算符重载 您可以重定义或重载 C# 中内置的运算符.因此,程序员也可以使用用户自定义类型的运算符.重载运算符是具有特殊名称的函数,是通过关键字 operator 后跟运算符的符号来定义的.与其 ...

  5. UVA557 汉堡 Burger

    题面 https://www.luogu.org/problemnew/show/UVA557 这里顺便整理一下二维格点随机游走问题. 遇到这种问题时,需注意分母的计算问题. 设x为起点到终点的距离. ...

  6. 未能加载文件或程序集“LinqToExcel”或它的某一个依赖项。试图加载格式不正确的程序。

    未能加载文件或程序集“*”或它的某一个依赖项.试图加载格式不正确的程序. 原因:操作系统是64位的,但发布的程序引用了一些32位的ddl,所以出现了兼容性的问题解决方案一:如果是64位机器,IIS—— ...

  7. java并发编程:线程安全管理类--原子操作类--AtomicLongFieldUpdater<T>

    1.类 AtomicLongFieldUpdater<T> public abstract class AtomicLongFieldUpdater<T> extends Ob ...

  8. mongodb的capped Collection集合

    db.createCollection(name, {capped: true, autoIndexId: true, size: 1000, max :100} ) name:集合的名字 cappe ...

  9. 快速切题 sgu105. Div 3 数学归纳 数位+整除 难度:0

    105. Div 3 time limit per test: 0.25 sec. memory limit per test: 4096 KB There is sequence 1, 12, 12 ...

  10. git reset --hard和git revert命令

      git reset --hard和git revert命令   git误操作时可以用git reset –hard 去撤销这次修改, 但是这样做也有问题,可能在之前本地有没有提交的修改也都消失了, ...