http://codeforces.com/contest/368/problem/B

从后往前找一遍就可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
using namespace std; int dp[maxn];
int n,m;
int a[maxn];
bool vis[maxn]; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,,sizeof(dp));
memset(vis,false,sizeof(vis));
int t1=;
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(int i=n; i>=; i--)
{
if(!vis[a[i]])
{
vis[a[i]]=true;
t1++;
dp[i]=t1;
}
else
{
dp[i]=t1;
}
}
for(int i=; i<=m; i++)
{
int x;
scanf("%d",&x);
printf("%d\n",dp[x]);
}
}
return ;
}

cf B. Sereja and Suffixes的更多相关文章

  1. B. Sereja and Suffixes(cf)

    http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...

  2. 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 ...

  3. Sereja and Suffixes(思维)

    Sereja and Suffixes Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  4. B. Sereja and Suffixes

    B. Sereja and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #215 (Div. 2) B. Sereja and Suffixes

    #include <iostream> #include <vector> #include <algorithm> #include <set> us ...

  6. CF 314C Sereja and Subsequences(树状数组)

    题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...

  7. CodeForces 368B Sereja and Suffixes

    题意:给你一个序列,问你从l位置到结尾有多少个不同的数字. 水题,设dp[i]表示从i位置到结尾不同数字的个数,那么dp[i] = dp[i+1] + (vis[a[i]] == 0),在O(n)时间 ...

  8. Sereja and Suffixes

    Codeforces Round #215 (Div. 2) B:http://codeforces.com/problemset/problem/368/B 题意:给你一个序列,然后查询i--n中没 ...

  9. cf D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D #include <cstdio> #include <cstring> #includ ...

随机推荐

  1. Android Canvas.drawText方法中的坐标参数的正确解释

    摘要 canvas.drawText(www.jcodecraeer.com, x, y, paint); x和y参数是指定字符串中心的坐标吗?还是左上角的坐标?这个问题的直观印象应该是左上角的坐标, ...

  2. Python web.py 实例和源码分析:

    示例: http://jyd.me/python/cookie-and-session/ simple to do:http://simple-is-better.com/news/309 http: ...

  3. php 读取 word

    ---恢复内容开始--- 首先安装com扩展: php.ini php.ini 确保有此语句 [PHP_COM_DOTNET] extension=php_com_dotnet.dll   php.i ...

  4. nfs:server 172.168.1.22 not responding,still trying问题解决方法 平台为RealARM 210平台

    nfs:server 172.168.1.22 not responding,still trying问题解决方法 ,平台为RealARM 210平台. 这里的问题是在使用nfs挂载文件系统时遇到的, ...

  5. 【转】Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)

    原文网址:http://embed.21ic.com/software/android/201403/31603.html 1 :Android中Spinner下拉列表(使用ArrayAdapter和 ...

  6. sql sever 模糊查询 除了like还有PATINDEX

    返回模式在指定表达式中第一次出现的起始位置:如果在所有有效的文本和字符数据类型中都找不到该模式,则返回零. USE AdventureWorks2012; GO SELECT PATINDEX('%e ...

  7. 数据加密算法---base64

    简介 base64是把8位字符打散,转换成不被人直接识别的形式,严格来说它并不是加密算法,只能算做一种编码方式 原理 首先准备64个字符数组做为“数组库” ['A', 'B', 'C', ... 'a ...

  8. 《Node.js开发指南》知识整理

    Node.js简介 Node是一个可以让JavaScript运行在服务器端的平台,抛弃了传统平台依靠多线程来实现高并发的设计思路,而采用单线程.异步式I/O.事件驱动式的程序设计模型. 安装和配置No ...

  9. jquery next nextAll nextUntil siblings的区别

    next:紧挨着$('')的一个元素 nextAll:在$('')以后的所有的同辈元素 nextUntil:until有直到...之前的意思,所以他表示$('')以后的所有的同辈元素,不过要在next ...

  10. zepto笔记

    $.contains: 判断节点是否存在的很好方式[另一个提供类似功能的函数是has] $.grep: 过滤数组 $.type: 获取变量类型 $.closest: 返回最先匹配到的祖先元素 $.ma ...