Codeforces Round #215 (Div. 2) B:http://codeforces.com/problemset/problem/368/B

题意:给你一个序列,然后查询i--n中没有重复元素的个数。

题解:从右到左递推一遍可以了,很简单的递推。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e5+;
int n,t,m;
int a[N];
int ans[N];
bool visit[N];
int main(){
while(~scanf("%d%d",&n,&m)){
memset(ans,,sizeof(ans));
memset(a,,sizeof(a));
memset(visit,,sizeof(visit));
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
ans[n]=;
visit[a[n]]=;
for(int i=n-;i>=;i--){
if(!visit[a[i]]){
ans[i]=ans[i+]+;
visit[a[i]]=;
}
else
ans[i]=ans[i+];
}
for(int i=;i<=m;i++){
scanf("%d",&t);
printf("%d\n",ans[t]);
}
}
}

Sereja and Suffixes的更多相关文章

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

  2. Sereja and Suffixes(思维)

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

  3. B. Sereja and Suffixes

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

  4. B. Sereja and Suffixes(cf)

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

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

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

  6. CodeForces 368B Sereja and Suffixes

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

  7. cf B. Sereja and Suffixes

    http://codeforces.com/contest/368/problem/B 从后往前找一遍就可以. #include <cstdio> #include <cstring ...

  8. CF380C. Sereja and Brackets[线段树 区间合并]

    C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. echo '.SUFFIXES: .cpp' >> ${OUTPUT_FILE}

    当前makefile或shell内支持文件后缀的类型列表,意思是文件支持.cpp结尾的类型,并且将他,输出到OUTPUT_FILE函数. 见网上有人说: “makefile中 .SUFFIXES: . ...

随机推荐

  1. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  2. Qt自定义控件(插件)并添加到QtDesigher

    之前使用Qt的时候都是手写代码的(因为批量按钮可以使用数组实现),但当界面越来越复杂时,这种开发效率就太低了; 后来就开始使用QtDesigner,但要使QtDesigner支持我自己写的控件,需要提 ...

  3. MapReduce实战:查找相同字母组成的单词

    1.项目需求 一本英文书籍包含成千上万个单词,现在我们需要在大量的单词中,找出相同字母组成的所有单词 2.数据集 下面是一本英文书籍截取的一部分单词内容(书籍内容是随意写的,主要目的是实现这种需求) ...

  4. 去掉android点击事件产生的半透明蓝色背景

    在wap开发过程当中,当你点击一个链接或者通过Javascript定义的可点击元素的时候,它就会出现一个半透明的蓝色背景,若要重设这个表现 ,可以利用css3: *{ -webkit-tap-high ...

  5. 简单回顾C++中的字符串

    C++中有两种字符串形式,一种是C语言字符数组,一般可以使用 char*指针来操作它:另一种是C++中基于标准库的string类型,这算是更高层次的抽象数据类型. 主要讨论一下string类型,既然是 ...

  6. Linux下长时间ping网络加时间戳并记录到文本(转)

    [root@test ~]# ping 192.168.2.1 -c 10 PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.64 bytes f ...

  7. win7、xp下Meclipse SVN用户名修改

    Meclipse SVN用户名修改,在网上查找后发现如下方法: 1.查看你的Eclipse中使用的是什么SVNInterface windows>preference>Team>SV ...

  8. Hadoop的读写类调用关系_图示

  9. hadoop-0.20-集群搭建___实体机通过SSH访问基于VM安装的Linux

    不得不说LZ在最开始搭建hadoop的时候,由于VM中的网段配置和本地IP地址没有配置好, 所以一直都在使用 VM的共享文件夹的功能, 以至于集群搭建好之后,只有namenode主机可以实现共享的功能 ...

  10. Xcode断点的一些黑魔法

    转自 只会左键断点?是时候试试这样那样断点了 编码不能没调试,调试不能没断点(Break Point).XCode的断点功能也是越来越强大. 基本断点 如下图,这种是最常用的断点,也是最容易设置.左键 ...