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. android 51 有序广播

    无序广播:一条广播发送出去,多个接收者接收没有顺序.有序广播:广播接收者可以设置优先级,优先级高的先收到广播.有序广播可以设置优先级. mainActivity.java package com.sx ...

  2. rsyslog官方文档

    http://www.rsyslog.com/doc/v8-stable/configuration/index.html

  3. 覆盖equals的时候总要覆盖hashCode

    import java.util.HashMap; public class Student { private String name ; private String id; public Stu ...

  4. c#正则表达式采集数据

    protected void Page_Load(object sender, EventArgs e){ StringBuilder MyStringBuilder = new StringBuil ...

  5. one way WebService

    WSDL支持4种消息交换方式:   1)单向(One-way):服务端接收消息:   2)请求响应(Request-response):服务端点接收请求消息,然后发送响应消息:   3)要求应答(So ...

  6. Axis,axis2,Xfire以及cxf对比 (转)

    Axis,axis2,Xfire以及cxf对比   http://ws.apache.org/axis/ http://axis.apache.org/axis2/java/core/ http:// ...

  7. tomcat的webapp下的root文件夹的作用是什么

    1.基本一样..只是表示不同的tomcat的http路径而已. root目录默认放的是tomcat自己的一个项目,如:http://localhost:8080/默认访问root项目 对于webapp ...

  8. 玩转CSLA.NET小技巧系列一:跳转页面丢失session,如何解决

    很少写代码,最近在写代码被登录难倒了,这丫的一直在跟我较劲 每次登录完跳转到首页后还是未登录状态 if (ModelState.IsValid) { bool isSuccess = FI.Finan ...

  9. 层模型--绝对定位(position:absolute)

    如果想为元素设置层模型中的绝对定位,需要设置position:absolute(表示绝对定位),这条语句的作用将元素从文档流中拖出来,然后使用left.right.top.bottom属性相对于其最接 ...

  10. WebSocket基于javaweb+tomcat的简易demo程序

    由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪 ...