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. SAE 上传根目录不存在!请尝试手动创建:./Uploads/Picture/

    请在Application\Common\Conf\config.php中,添加'FILE_UPLOAD_TYPE' => 'Sae'

  2. [RxJS] Aggregating Streams With Reduce And Scan using RxJS

    What is the RxJS equivalent of Array reduce? What if I want to emit my reduced or aggregated value a ...

  3. MySQL 5.6初始配置调整

    原文链接: What to tune in MySQL 5.6 after installation原文日期: 2013年09月17日翻译日期: 2014年06月01日翻译人员: 铁锚 随着 大量默认 ...

  4. 了解ANSI编码

    ANSI:American National Standards Institute:美国国家标准学会 ANSI编码:为使计算机支持更多语言,不同国家和地区分别制定了符合自身的外文字符延伸编码方式(如 ...

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

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

  6. c++矩阵运算

    优化了一些算法 #pragma once #include <iostream> #include <iomanip> #include <string> #def ...

  7. poj 1821 Fence 单调队列优化dp

    /* poj 1821 n*n*m 暴力*/ #include<iostream> #include<cstdio> #include<cstring> #incl ...

  8. codevs 2149 矩形周长(暴力扫描线)

    /* 暴力应该很好理解 不多说了 至于线段树维护的嘛 还没看懂 哪天突然想明白了在写吧 */ #include<iostream> #include<cstdio> #incl ...

  9. Unity3D GUI学习

    Unity3D内置有GUI, 首先,使用GUI实现一个按钮,并且点击实现触发, void OnGUI() { //GUI.Button (new Rect (10,10,50,50), "n ...

  10. Eclipse清除SVN密码

    1. Eclipse/Subclipse并不会记录用户名及密码, SVN密码是由SVN客户端(JavaHL or SVNKit)负责维持的 2. 可查看Eclipse的Preferences中SVN属 ...