Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map
B. Sereja and Suffixes
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/problemset/problem/368/B
Description
Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each li.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the array elements.
Next m lines contain integers l1, l2, ..., lm. The i-th line contains integer li (1 ≤ li ≤ n).
Output
Print m lines — on the i-th line print the answer to the number li.
Sample Input
10 10
1 2 3 4 1 2 3 4 100000 99999
1
2
3
4
5
6
7
8
9
10
Sample Output
6
6
6
6
6
5
4
3
2
1
HINT
题意
n个数,m次询问
每次询问,问你[l,n]有多少不同的数字
题解:
用map就好了
我们离线做
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1050005
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int ans[maxn];
int a[maxn];
map<int,int> H;
int flag=;
int main()
{
int n=read(),m=read();
for(int i=;i<=n;i++)
{
a[i]=read();
H[a[i]]++;
if(H[a[i]]==)
flag++;
}
for(int i=;i<=n;i++)
{
ans[i]=flag;
H[a[i]]--;
if(H[a[i]]==)
flag--;
}
for(int i=;i<=m;i++)
{
int x=read();
printf("%d\n",ans[x]);
}
}
Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map的更多相关文章
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
#include <iostream> #include <vector> #include <algorithm> #include <set> us ...
- 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 ...
- 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+ ...
- Codeforces Round #215 (Div. 2) C. Sereja and Algorithm
#include <iostream> #include <vector> #include <algorithm> #include <string> ...
- Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并
题目链接:http://codeforces.com/contest/381/problem/E E. Sereja and Brackets time limit per test 1 secon ...
- 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 ...
随机推荐
- 什么是SPF?如何设置企业邮箱的SPF呢?(TXT记录)
什么是SPF? (Sender Policy Framework) 的缩写,一种以IP地址认证电子邮件发件人身份的技术,是非常高效的垃圾邮件解决方案. 接收邮件方会首先检查域名的SPF记录,来确定 ...
- Golang几个常用记录日志对比
go语言有一个标准库,log,提供了最基本的日志功能,但是没有什么高级的功能,如果需要高级的特性,就需要使用第三方包,下面是一些候选的包: go_tmlog https://code.google.c ...
- CDB和PDB基本管理
CDB和PDB基本管理 这篇文章主要介绍CDB和PDB的基本管理,资料来源oracle官方. 基本概念: Multitenant Environment:多租户环境 CDB(Container Dat ...
- 精品手游《里奥的财富》高清版逆向移植家用机与PC平台(转)
冒险动作游戏<里奥的财富>于去年10月登陆移动平台,曾荣获App Store“年度优秀游戏”.开发商宣布将推出其HD版本,近期会陆续登陆PS4.PC.MAC.Xbox One平台. 由瑞典 ...
- lego blocks
1.题目描述 https://www.hackerrank.com/challenges/lego-blocks 2.解法分析 这题乍看一下觉得应该可以用动态规划来做,但是却死活想不到最优子结构,在网 ...
- Windows Azure 虚拟网络配置(Point to Site)
说明:本文以Azure国际版为例,中国版在网络位置会存在一定差异. 1. 场景 虚拟网络为我们提供了在Windows Azure云计算环境上构建网络定义的能力,通过虚拟网络,我们可以方便地将Windo ...
- HBase应用场景
适用场景 列族结构经常调整 高并发写入 结构化数据及半结构化数据 Key-Value存储 有序存储 固定集合(多版本) 定时删除记录(TTL) 不适用场景 事务 join,union,groupb ...
- 自己封装的Socket组件,实现服务端多进程共享Socket对象,协同处理客户端请求
DotNet.Net.MySocket是SLB.NET(Server Load Balance服务器负载均衡)项目中的核心组件. 在实际的项目中发现,单进程的服务端处理高并发的客户请求能力有限. 所以 ...
- CSStickyHeaderFlowLayout collectionView headerView 悬浮
github:https://github.com/levyleo/CSStickyHeaderFlowLayout iOS 10 使用时会出现崩溃:https://github.com/CSStic ...
- sprite常用操作
,锚点 锚点就是所有旋转,移动,缩放的参考点.cocos2-x中默认的锚点是中心点.锚点用比例来表示范围为0-,(,)点代表左下点,(,)代表右上点.设置的函数为setAnchorPoint(ccp( ...