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 ...
随机推荐
- Redis pipeline and list
Redis Redis 是一个开源的基于内存的数据结构存储器.通常可作为数据库,缓存和消息中介.它支持的数据结构有:字符串.哈希表.列表.集合.支持范围查询的有序集合.位图.hyperloglogs和 ...
- UIButton 在UIScrollView里面 点击效果不明显的问题
self.scrollView.delaysContentTouches = NO; -(BOOL)touchesShouldCancelInContentView { return YES; }
- <面试经典题>输入框的功能测试点分析
(废话几句:这个是网上找来的一份模板,高亮部分为自己修改内容,且此面试题很像当年高考的“必考题”性质,触类旁通吧) 1. 输入框UI是否预计了输入内容长度(尽量完整的显示输入内容): 2. 输入框之前 ...
- [转]inux之touch命令
转自:http://www.2cto.com/os/201309/242518.html Linux学习之touch命令 Linux的touch命令一般用来更改文档或目录的日期时间,包括存取时间和 ...
- java webservice AXIS
1. eclipse axis 插件下载地址 http://archive.apache.org/dist/ws/axis2/tools/1_4_1/ 一个是代码生成插件 axis2-ecli ...
- STL1-unordered_map
最近几天我要整理一下遇到的STL的函数,本来其实我是没有打算学的,认为用C就完全可以实现,干嘛要记那么多复杂的函数呢,所以我之前的做法都是将常用的C函数自己做了一个lib库,使用起来也是蛮方便的呢,但 ...
- Package inputenc Error: Unicode char \u8: not set up for use with LaTeX.
用TexStudio编辑文档时,不知是多加了空格还是啥,总是提示如下错误: Package inputenc Error: Unicode char \u8: not set up for use w ...
- proguard 混淆android代码
官网 http://proguard.sourceforge.net/#manual/examples.html android 2.3后,新建的project默认就有一个project.proper ...
- js运动 运动效果留言本
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- Shell脚本文件中常用的操作语句
1. 清空文件中的内容 cat /dev/null >> /var/log/messages 2. 脚本中判断用户是不是root用户 ROOT_UID = 0 # ...