cf B. Sereja and Suffixes
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的更多相关文章
- B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...
- 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 ...
- Sereja and Suffixes(思维)
Sereja and Suffixes Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- B. Sereja and Suffixes
B. Sereja and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
#include <iostream> #include <vector> #include <algorithm> #include <set> us ...
- CF 314C Sereja and Subsequences(树状数组)
题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...
- CodeForces 368B Sereja and Suffixes
题意:给你一个序列,问你从l位置到结尾有多少个不同的数字. 水题,设dp[i]表示从i位置到结尾不同数字的个数,那么dp[i] = dp[i+1] + (vis[a[i]] == 0),在O(n)时间 ...
- Sereja and Suffixes
Codeforces Round #215 (Div. 2) B:http://codeforces.com/problemset/problem/368/B 题意:给你一个序列,然后查询i--n中没 ...
- cf D. Sereja ans Anagrams
http://codeforces.com/contest/368/problem/D #include <cstdio> #include <cstring> #includ ...
随机推荐
- GS1011无线模块的使用简介。
一.硬件说明: 只是用电脑的串口助手与之通信,利用了max232进行电平转换.是用模块的UART0作为通信接口. 模块引脚 接点 说明 1.17.32.48 GND 模块地 9 3.3V VB ...
- HDOJ 1197 Specialized Four-Digit Numbers
Problem Description Find and list all four-digit numbers in decimal notation that have the property ...
- JBossESB教程(二)——将JBossESB部署到JBossAS中
前言 上篇讲了JBossESB的环境搭建,但是细心的同学会发现,我们在添加JBoss AS的时候,实际上添加的是jbossesb-server,而这个里面是没有EJB的支持的.如果我们想要使开发环境能 ...
- 解决Xcode8 输出一对字符串问题
在Product->Scheme->Edit Scheme->Run->Environment Variables下添加键:OS_ACTIVITY_MODE, 值:Disabl ...
- 你需要知道的九大排序算法【Python实现】源码
#coding: utf-8 #!/usr/bin/python import randomimport math #随机生成0~100之间的数值def get_andomNumber(num): l ...
- 【ThinkingInC++】64、重载new和delete,来模仿内存的分配
/** * 书本:[ThinkingInC++] * 功能:重载new和delete.来模仿内存的分配 * 时间:2014年10月5日14:30:11 * 作者:cutter_point */ #in ...
- Java和C++的不同
现在一边继续深入C++,一边学习Java,为了学习得更加透彻,不断比较两者之间的不同,以后会慢慢继续增加. 1.在多态的实现上,C++需要利用关键字virtual,而Java不需要,因为在Java中, ...
- Python购物车的实现课程
需求: 1.用户输入工资收入 2.打印商品列表 3.用户选择商品,不断的加入购物车 4.检测用户余额,直接捐款,不足提示余额不足 5.允许主动退出,退出时,打印已购商品列表 重点方法: 打印列表下标的 ...
- jquery之onchange事件2
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- wpf-DataTemplate应用
在WPF中,决定数据外观的是DataTemplate,即DataTemplate是数据内容的表现形式,一条数据显示成什么样子,是简单的文本还是直观的图形,就是由DataTemplate决定的.下面通过 ...