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. MVC4.0中ViewBag、ViewData、TempData和ViewModel几种传值方式的区别

    MVC框架实现了数据的分离,使页面看起来更加的简洁,MVC4.0中Controller和View的数据传输有上边这几种方式,今天我们来探讨下这几种方式的却别. 一:ViewBag和ViewData V ...

  2. Response.Expires 属性 (转载于疯狂客的BLOG)

    Expires 属性 Expires 属性指定了在浏览器上缓冲存储的页距过期还有多少时间.如果用户在某个页过期之前又回到此页,就会显示缓冲区中的版本 语法 Response.Expires [= nu ...

  3. matrix矩阵求逆 与解方程模板 留做备用 (有bug,待补充)

    // // main.cpp // 矩阵求逆 // // Created by 唐 锐 on 13-6-20. // Copyright (c) 2013年 唐 锐. All rights reser ...

  4. Mysql auto_increment 重新计数(让id从1开始)

    当清空一个表的时候,重新插入数据,发现auto_increment属性的字段计数不是从1开始的时候,可以使用以下命令   方法一 delete from test; alter table `test ...

  5. hadoop2.2.0的ha分布式集群搭建

    hadoop2.2.0 ha集群搭建 使用的文件如下:    jdk-6u45-linux-x64.bin    hadoop-2.2.0.x86_64.tar    zookeeper-3.4.5. ...

  6. 解决Qt5.7.0 cannot find -lGL

    很久没用Qt了,这次要做一个协议编辑器,在ubuntu 14.04上安装了最新版本的Qt 5.7.0.界面改用扁平化风格,第一感觉还不错.按默认步骤创建了一个gui程序,编译运行,报了一个错:cann ...

  7. http缓存策略

    http://foofish.net/blog/95/http-cache-policy

  8. mybatis与spring的整合

    今天是mybatis的最后一天,也是最为重要的一天,mybatis与spring整合,(spring相关知识我会抽一个大的模块进行讲解). 首先加入Spring的依赖 <dependency&g ...

  9. jquery之遍历展示title

    //遍历展示title {field:'couponsList',title:'优惠劵类型',width:250,align:'center',sortable:true, formatter:fun ...

  10. AnkhSVN 中文版 支持VS2015

    简介:AnkhSVN是一款在VS中管理Subversion的插件,您可以在VS中轻松的提交.更新.添加文件,而不用在命令行或资源管理器中提交,而且该插件属于开源项目. 这个版本是简体中文的重新编译版本 ...