首页 > 其他分享 >CodeForces - 367B Sereja ans Anagrams (map)

CodeForces - 367B Sereja ans Anagrams (map)

时间:2023-04-19 15:34:47浏览次数:50  
标签:map Anagrams ... 367B int integers ans include define

CodeForces - 367B Sereja ans Anagrams
Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence bconsists 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 nm 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 b1b2, ..., 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.

Sample Input

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
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<map>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 200010
#define M 1000000007
using namespace std;
int a[N];int ans[N];
int n,m,p;
map<int,int>A,B;
void ins(int x,int t)
{
	B[x]+=t;
	if(!B[x])
		B.erase(x);
}
int main()
{
	int x,i,j,k;
	scanf("%d%d%d",&n,&m,&p);
	if(1ll*(m-1)*p+1>n)
		printf("0\n");
	else
	{
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(i=1;i<=m;i++)
		{
			scanf("%d",&x);
			A[x]++;
		}
		int kk=0;
		for(i=1;i<=p;i++)
		{
			B.clear();
			for(j=i;j<=n;j+=p)
			{
				ins(a[j],1);
				k=j-m*p;
				if(k>0)
					ins(a[k],-1);
				k=j-(m-1)*p;
				if(k>0&&B==A)
					ans[++kk]=k;
			}
		}
		sort(ans+1,ans+kk+1);
		printf("%d\n",kk);
		for(i=1;i<=kk;i++)
			printf("%d ",ans[i]);
	}
	return 0;	
}

标签:map,Anagrams,...,367B,int,integers,ans,include,define
From: https://blog.51cto.com/u_16079508/6206438

相关文章

  • 获取java HashMap 的容量和阈值
      publicstaticvoidmain(String[]args)throwsException{HashMap<Integer,Integer>m=newHashMap<>(9);Class<?>mapType=m.getClass();Fieldthreshold=mapType.getDeclaredField("threshold");......
  • 4月18日set与map的学习
    之前学习过string,list,vector,deque,和两种适配器queue和stack,这些都是线性表的数据结构;而今天学习的map和set他们的底层是二叉搜索树,或者平衡二叉搜索树。首先是set她没有键值对,并且不能出现重复元素,比如当插入两个一时,他只会插入一个一,所以可以用作数组去重。 比如上图当插......
  • 如何计算 目标检测任务的 AP 以及 mAP 指标?
    AP50:50的的意思是IOU的阈值是0.5。先算AP,AP是针对某一类的,表示不同置信度下的PR值的平均,也就是通过不同置信度得到一条PR曲线,曲线下的面积就是AP。这里的置信度是模型输出的条件概率,即是该类的条件下的概率。比如对于persion这一类,模型经过NMS得到一些......
  • Redis高级 哈希类型、列表类型、集合类型、有序集合(zset)、慢查询、pipeline与事务
    哈希类型###1---hget,hset,hdelhgetkeyfield#获取hashkey对应的field的value时间复杂度为o(1)hsetkeyfieldvalue#设置hashkey对应的field的value值时间复杂度为o(1)hdelkeyfield#删除hashkey对应的field的值时间复杂度为o(1)#测试hsetuser:1:infoage......
  • 【Redis】哈希类型 列表类型 集合类型 有序集合 慢查询 pipeline与事务 发布订阅 Bitm
    目录昨日回顾今日内容1哈希类型2列表类型3集合类型4有序集合(zset)5慢查询6pipeline与事务7发布订阅8Bitmap位图9HyperLogLog作业昨日回顾#1redis介绍 -特性#速度快:10wops(每秒10w读写),数据存在内存中,c语言实现,单线程模型#持久化:rdb和aof#多种数据结......
  • Map和Vector
    PAT甲级-1016sanpleinput10101010101020202015151515151515203020151510101010CYLL01:01:06:01on-lineCYLL01:28:16:05off-lineCYJJ01:01:07:00off-lineCYLL01:01:08:03off-lineCYJJ01:01:05:59on-lineaaa01:01:01:03on-lineaaa......
  • 2023-4-18补缺map
    map是STL的一个关联容器,它提供一对一的hash。第一个可以称为关键字(key),每个关键字只能在map中出现一次;第二个可能称为该关键字的值(value);map以模板(泛型)方式实现,可以存储任意类型的数据,包括使用者自定义的数据类型。Map主要用于资料一对一映射(one-to-one)的情況,map內部的实......
  • redis 二、(哈希类型,列表类型,集合类型,有序集合,pipline机制,发布订阅,bitmap位图,HyperLogL
    目录Redis一、哈希类型二、列表类型三、集合类型四、有序集合五、慢查询六、pipline与事务七、发布订阅八、bitmap位图九、HyperLogLogRedis一、哈希类型###1---hget,hset,hdelhgetkeyfield#获取hashkey对应的field的value时间复杂度为o(1)hsetkeyfieldvalue#设......
  • uniapp 集成 sentry,并上传sourcemap,定位错误
    具体见:https://blog.csdn.net/weixin_49192390/article/details/113989218?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168178969316800197063528%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168178969316800197063528&a......
  • Hadoop的生态体系,HDFS和MapReduce等的具体介绍
    Hadoop的两大核心就是HDFS和MapReduce,而整个Hadoop的体系结构主要是通过HDFS的分布式存储作为底层数据支持的。并且会通过MapReduce来进行计算分析。Hadoop1.x的核心:HadoopCommonHadoopDistributedFileSystem(HDFS)HadoopMapReduceHadoop2.x的核心:HadoopCommonHadoopDistribu......