题意:给你一个序列,问你从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. Putty终端 模拟 远程登录 虚拟机Linux

    1.虚拟机设置 虚拟机设置->网络适配器->选择Host-only:与主机共享一个私有网络 桥接.NAT.Host-only三种网络模式的说明: (1)桥接:表示在局域网内是一台真实的系统 ...

  2. mysql---union的用法

    union的作用很简单用来合并两条sql的结果集 语法: SQL1 UNION SQL2 现有一张价格表 要求:求出价格低于2000和价格高于3000的商品,不能用or和not between--an ...

  3. UniqueID,页面子控件唯一标示

    aspx: <form id="form1" runat="server">     <asp :Repeater ID="MyDa ...

  4. SET ANSI_NULLS ON

    Transact-SQL 支持在与空值进行比较时,允许比较运算符返回 TRUE 或 FALSE. 通过设置 ANSI_NULLS OFF 可将此选项激活.当 ANSI_NULLS 为 OFF 时,如果 ...

  5. 微信开发之开发环境搭建( visual studio 2015we + IIS express + ngrok)

    1. 申请个人测试使用的微信订阅号 https://mp.weixin.qq.com 可注册微信订阅号. 不会?请自行百度. 2. 安装 ngrok 微信开发首先要解决如何让微信链接到本地开发环境.有 ...

  6. C#微信登录-电脑版扫描二维码登录

    像京东,一号店等网站都实现了用微信来登录的功能,就是用手机上的微信扫一扫网站上的二维码,微信上确认后,即可自动用微信的帐号登录网站. 一.创建网站应用 在微信开放平台创建一个网站应用 https:// ...

  7. UGUI-组件

    2015-06-22 UGUI 组件 Canvas 画布 The Canvas component represents the abstract space in which the UI is l ...

  8. c# int? i = null

    语法 T? 是 Nullable<T>的简写. Nullable<int> i = null; 等价于 int? i = null; 在Nullable赋值给非Nullable ...

  9. 朴素贝叶斯文本分类java实现

    package com.data.ml.classify; import java.io.File; import java.util.ArrayList; import java.util.Coll ...

  10. ul 、ol li 继承原有样式的问题

    如: 1.为什么我的服务器无法远程了? 2.为什么我的服务器总是自动重启? 3.为什么我的服务器总是自动重启? 以前写这种类型的列表,都是自己用键盘输入这些数字,其实不然,ul .ol li本身就自带 ...