题意:给你一个序列,问你从l位置到结尾有多少个不同的数字。

水题,设dp[i]表示从i位置到结尾不同数字的个数,那么dp[i] = dp[i+1] + (vis[a[i]] == 0),在O(n)时间内得出答案。

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 100010;
int vis[MAXN], dp[MAXN], a[MAXN];
int main(){
int n, m, l;
#ifndef ONLINE_JUDGE
freopen("in.cpp", "r", stdin);
#endif
while(~scanf("%d%d", &n, &m)){
memset(dp, 0, sizeof dp);
memset(vis, 0, sizeof vis);
for(int i = 1;i <= n;i ++) scanf("%d", a + i);
dp[n] = 1, vis[a[n]] = 1;
for(int i = n-1;i > 0;i --){
if(!vis[a[i]]){
dp[i] = dp[i+1] + 1;
vis[a[i]] = 1;
}else dp[i] = dp[i+1];
}
for(int i = 0;i < m;i ++){
scanf("%d", &l);
printf("%d\n", dp[l]);
}
}
return 0;
}

CodeForces 368B 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. B. Sereja and Suffixes(cf)

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

  3. Sereja and Suffixes(思维)

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

  4. Codeforces 432D Prefixes and Suffixes(KMP+dp)

    题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出 ...

  5. B. Sereja and Suffixes

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

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

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

  7. codeforces 314E Sereja and Squares

    discription Sereja painted n points on the plane, point number i (1 ≤ i ≤ n) has coordinates (i, 0). ...

  8. Codeforces 432D Prefixes and Suffixes kmp

    手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit ...

  9. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

随机推荐

  1. 【转】C#.net拖拽实现获得文件路径

    C#.net拖拽实现获得文件路径 作者Attilax ,  EMAIL:1466519819@qq.com 思路: 通过DragEnter事件获得被拖入窗口的“信息”(可以是若干文件,一些文字等等), ...

  2. javascript基础DOM操作

    DOM 中的三个字母,D(文档)可以理解为整个 Web 加载的网页文档:O(对象)可以理解为类似 window 对象之类的东西,可以调用属性和方法,这里我们说的是 document对象:M(模型)可以 ...

  3. linux sed 批量替换多个文件中的字符

    格式: sed -i "s/查找字段/替换字段/g" `grep 查找字段 -rl 路径` linux sed 批量替换多个文件中的字符串 sed -i "s/oldst ...

  4. Winodws live writer

    发布一篇试试.

  5. cocos2dx3.4 保存json文件

    头文件: #include "json/document.h" #include "json/stringbuffer.h" #include "js ...

  6. Elasticsearch强大的聚合功能Facet

    在常规数据库中,我们都知道有一个sql就是group,分组.如果主表只有对应的一个列记录的分组的ID,那么还好统计,比如说每本书book表,有一个分类catId,记录是属于哪一类的书,那么直接按照ca ...

  7. MongoDB 覆盖索引查询

    MongoDB 覆盖索引查询 官方的MongoDB的文档中说明,覆盖查询是以下的查询: 所有的查询字段是索引的一部分 所有的查询返回字段在同一个索引中 由于所有出现在查询中的字段是索引的一部分, Mo ...

  8. Win7 & Win 8系统更新失败的解决

    转自:Win 8系统更新失败的解决(原创) 这几天win 8又出了一大堆更新,而且是一更新完就要重启,重启之后照例要进入更新包的安装过程.不爽的是,屡屡在重启后出现"配置Windows更新失 ...

  9. android 开发adb server is out of date 解决方案

    查看到底是哪个端口给占用了 输入红色部分命令 C:\Users\xxxxxx>netstat -ano | findstr "5037" TCP    127.0.0.1:5 ...

  10. php nl2br() 函数

    nl2br() 函数在字符串中的每个新行 (\n) 之前插入 HTML 换行符 (<br />).