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. Shell循环输入符合条件为止

    提供用户输入,直到输入d/D/r/R为止. #!/bin/bash ]; do echo -n "(D)ebug or (R)elease?" read select_build_ ...

  2. git查看本地分支关联(跟踪)的远程分支之间的对应关系,本地分支对应哪个远程分支

    git branch -vv: [root@realserver git-test]# git branch -vv  bug    23043a7 add new.txt master.* dev  ...

  3. PHP函数总结 (四)

    <?php/** * 引用参数: * 1.PHP默认按值传递参数,父程序(调用函数)与子程序(函数)的数值分别存储与不同的内存区块: * 2.引用传递参数,加符号 & :它是把父程序的数 ...

  4. Dynamic Web Module 3.1 requires Java 1.7 or newer. 错误解决方案

    在写代码的时候工程出现了这样奇怪的bug很是蛋疼啊,经过查询解决方法,终于解决了这些个问题. 下面是解决问题的方法,和大家分享一下 (1)确定你的java工程配置使用了java 7 右键单击你的工程p ...

  5. 『Sklearn』数据划分方法

    原理介绍 K折交叉验证: KFold,GroupKFold,StratifiedKFold, 留一法: LeaveOneGroupOut,LeavePGroupsOut,LeaveOneOut,Lea ...

  6. Leetcode 94

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  7. OAF 功能中的参数含义

    OA.jsp?OAFunc=POS_HT_SP_B_SUPP&OAPB=POS_SM_PRODUCT_BRANDING&OAHP=POS_SM_ADMIN_HOME&OASF= ...

  8. 使用UTL_SMTP发送中文邮件及使用UTL_TCP从附件服务器获取中文附件

    先上最重要的干货 发送邮件正文及主题的时候一定要使用convert重新编码 主题: utl_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw(c ...

  9. 使用kubernetes的deployment进行RollingUpdate

    rolling update,可以使得服务近乎无缝地平滑升级,即在不停止对外服务的前提下完成应用的更新. replication controller与deployment的区别 replicatio ...

  10. PHP 的 HTTP 认证机制

    PHP 的 HTTP 认证机制仅在 PHP 以 Apache 模块方式运行时才有效,因此该功能不适用于 CGI 版本.在 Apache 模块的 PHP 脚本中,可以用 header()函数来向客户端浏 ...