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 ...
随机推荐
- Net判断一个对象是否为数值类型 z
http://www.cnblogs.com/SkyD/p/4053461.html public static bool IsNumeric(this Type dataType) { if (da ...
- SQL求 交集 并集 差集
故事是这样的….. 故事情节: 表 tb_test 有两列, colA , colB; 求 colA , colB 的并交差集… -- 计算并集 SELECT DISTINCT colB FROM t ...
- MapReduce 中job.setJarByClass()方法的疑惑
在调试mr实例的时候,遇到如下的情况,如图所示 说明:就是我的mr程序类名称和我设置的setJarByclass()中设置的不一样,但是程序竟然没有报错!!!!当时把我吓尿了 疑惑:如果这样设置的话, ...
- 算法:最大子数组own
转载标明出处:http://i.cnblogs.com/EditPosts.aspx?postid=4726782&update=1 暴力法: // maxValue.cpp : 定义控制台应 ...
- C语言练习:第二大整数
问题描述 编写一个程序,读入一组整数(不超过20个),当用户输入0时,表示输入结束.然后程序将从这组整数中,把第二大的那个整数找出来,并把它打印出来.说明:(1)0表示输入结束,它本身并不计入这组整数 ...
- C++异常处理assert,throw,exit用法
常见的几个小细节问题. assert应用: 在现实世界中,我们脑袋时刻都在判断对与错,对的事情我们会继续深入下去,而错的事情我们会马上停止,那么在编程开发中我们如何赋予程序这种判断事物对错的能力呢?其 ...
- TV端产品设计法则和分析
对TV端产品设计的分析太特么少了.翻遍网络,大多也是针对UI设计的分析,这篇从产品设计的角度,梳理下现有的TV端产品设计法则,顺道做点分析.(前方多图,高能预警) 目录: 1. TV端产品使用场景 2 ...
- Git 提交后开始自动构建
设定Git仓库的钩子 一般路径为 xxx.git/hooks 参考文档 https://git-scm.com/docs/githooks 修改 post-receive #!/bin/bash wh ...
- 桶排序-Node.js
, , , , ]; var a = [], i; ; i < b.length; i++) { var num = b[i]; a[num] = a[num]||; a[num] ++; nu ...
- hdu4421-Bit Magic(2-SAT)
题意 根据图中公式由A[]构造B[][],现在给你B,问你存不存在一个数组A使之成立. 题解:对于每一位进行2-sat求解. 比赛半个小时时间,没做出来…… 一直T. 因为本身对算法不确定,所以也不知 ...