B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B
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 <stdio.h>
#include <string.h>
const int N=;
int hash[N],f[N],a[N],l[N];
int main()
{
int n,m,cnt = ;
scanf("%d %d",&n,&m);
memset(hash,,sizeof(hash));
for (int i = ; i <= n; i++)
scanf("%d",&a[i]);
for (int i = ; i <= m; i++)
scanf("%d",&l[i]);
for (int i = n; i >= ; i--)
{
hash[a[i]]++;
if (hash[a[i]]==)
cnt++;
f[i] = cnt;//表示从i到n的不同的元素个数
}
for (int i = ; i <= m; i++)
printf("%d\n",f[l[i]]);
return ;
}
B. Sereja and Suffixes(cf)的更多相关文章
- 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
B. Sereja and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standa ...
- cf B. Sereja and Suffixes
http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...
- 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 314 E. Sereja and Squares
E. Sereja and Squares http://codeforces.com/contest/314/problem/E 题意: 给你一个擦去了部分左括号和全部右括号的括号序列,括号有25种 ...
- CF 314C Sereja and Subsequences(树状数组)
题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...
随机推荐
- PowerDesigner16逆向工程生成PDM列注释(My Sql5.0模版)
一.编辑当前DataBase 选择DataBase——>edit Current DBMS...弹出如下对话框: 如上图,先解释一下: 根据红颜色框从上往下解释一下. 第一个红框是对应的修改的 ...
- Java多线程学习笔记(一)——多线程实现和安全问题
1. 线程.进程.多线程: 进程是正在执行的程序,线程是进程中的代码执行,多线程就是在一个进程中有多个线程同时执行不同的任务,就像QQ,既可以开视频,又可以同时打字聊天. 2.线程的特点: 1.运行任 ...
- PHP 之ip查询接口
/** * @param $ip 待查询的ip * @return mixed */ function getIpAddressInfo($ip) { $ipurl = 'http://api.ip1 ...
- php base64互转pdf
/* * base64转pdf */ function base642pdf($formTxt,$toPdf) { $file = file_get_contents($formTxt);//读 $d ...
- LINUX-查看进程内环境变量
ps -ef find PID cat /proc/$PID/environ | grep ENV
- ceph部署
一.部署准备: 准备5台机器(linux系统为centos7.6版本),当然也可以至少3台机器并充当部署节点和客户端,可以与ceph节点共用: 1台部署节点(配一块硬盘,运行ceph-depo ...
- 1 Excel
#region 设置页边距 //sheet.SetMargin(MarginType.LeftMargin, (double)0.6 / 3); //sheet.SetMargin(MarginTyp ...
- 利用open MP获取计算机核心数量的方法
openMP是一款普遍通用的并行计算编程模型,使用它通常能够充分利用多核计算的优势. 以下是一种能够测试核心数量的方法: std::cout << "parallel begin ...
- PAT 1057. Stack
Stack is one of the most fundamental data structures, which is based on the principle of Last In Fir ...
- [网络收集]20190528华为数通网络工程师认证HCIA-VRP的操作指导思维导图
>> >0 VRP基础 >1 命令行基础 >2 文件系统基础 >3 VRP系统管理