B. Sereja and Suffixes
1 second
256 megabytes
standard input
standard output
Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≤ li ≤ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, ..., n. Formally, he want to find the number of distinct numbers among ali, ali + 1, ..., an.?
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.
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).
Print m lines — on the i-th line print the answer to the number li.
10 10
1 2 3 4 1 2 3 4 100000 99999
1
2
3
4
5
6
7
8
9
10
6
6
6
6
6
5
4
3
2
1
#include<iostream>
using namespace std;
int n,m,a[],dp[],vis[];
int main()
{
while(cin>>n>>m)
{
for(int i=;i<n;i++)
{
cin>>a[i];
}
dp[n-]=;
for(int i=n-;i>=;i--)
{
if(vis[a[i]]==)
dp[i]=dp[i+]+;
else
dp[i]=dp[i+];
vis[a[i]]=; }
while(m--)
{
int t;
cin>>t;
cout<<dp[t-]<<endl;
}
}
return ;
}
B. Sereja and Suffixes的更多相关文章
- 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 ...
- Sereja and Suffixes(思维)
Sereja and Suffixes Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
#include <iostream> #include <vector> #include <algorithm> #include <set> us ...
- CodeForces 368B Sereja and Suffixes
题意:给你一个序列,问你从l位置到结尾有多少个不同的数字. 水题,设dp[i]表示从i位置到结尾不同数字的个数,那么dp[i] = dp[i+1] + (vis[a[i]] == 0),在O(n)时间 ...
- Sereja and Suffixes
Codeforces Round #215 (Div. 2) B:http://codeforces.com/problemset/problem/368/B 题意:给你一个序列,然后查询i--n中没 ...
- cf B. Sereja and Suffixes
http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...
- CF380C. Sereja and Brackets[线段树 区间合并]
C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...
- echo '.SUFFIXES: .cpp' >> ${OUTPUT_FILE}
当前makefile或shell内支持文件后缀的类型列表,意思是文件支持.cpp结尾的类型,并且将他,输出到OUTPUT_FILE函数. 见网上有人说: “makefile中 .SUFFIXES: . ...
随机推荐
- java如何从cmd运行并使用text文件作为输入源的总结
大家好,好几天没写东西了,又和大家见面了 首先,编译我们的.java文件,生成.class文件 使用命令 javac yourname.java 编译 然后使用java youname < yo ...
- [hdu3949]XOR(线性基求xor第k小)
题目大意:求xor所有值的第k小,线性基模板题. #include<cstdio> #include<cstring> #include<algorithm> #i ...
- 2018多校第九场1010 (HDU6424) 数学
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6424 解法:找规律.因为最多三项,a1^a2^a3可以拆成(a1+2)+(a2+1)*a3,然后建成数 ...
- 写一个函数封装printf用作trace
转自http://blog.csdn.net/coder_weisong/article/details/10285291 写一个函数封装printf用作trace 方法一: #inc ...
- 小组作业wordCountPro·
基本任务:代码编写+单元测试 (1) Github地址: https://github.com/LongtermPartner/ExtendWordCount (2) PSP表格: psp 2.1 ...
- Linux下面的IO模型
1. Linux下的五种I/O模型 阻塞I/O模型: 一直阻塞 应用程序调用一个IO函数,导致应用程序阻塞,等待数据准备好. 如果数据没有准备好,一直等待….数据准备好了,从内核拷贝到用户空 ...
- TCP/IP的三次握手和四次放手
一开始个人对于三次握手和四次挥手这个东西还是有时候会忘记,可能理解的不是非常深刻,所以今天就自己动手来记录一下这个知识点,方便以后查看.总结完之后发现总结的还是可以的哈哈. 三次握手建立连接 第一次: ...
- delphi xe6 让 ListView 在 Android 可回弹[根据龟山阿卍原创修改为xe6版本]
Delphi XE6 找出 FMX.Platform.Android.pas 档案,并复制到自己的 Project 路径里,找到 GetScrollingBehaviour 函数,修改成如下: uni ...
- JDBC行级锁
行级锁又称为悲观锁 for update 如下(必须要等这个for updaste事务执行完毕以后,剩下的sql语句才可以去执行)
- GUID介绍
GUID介绍 GUID(Global unique identifier)全局唯一标识符,它是由网卡上的标识数字(每个网卡都有唯一的标识号)以及 CPU 时钟的唯一数字生成的的一个 16 字节的二进制 ...