CodeForces 368B Sereja and Suffixes
题意:给你一个序列,问你从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的更多相关文章
- 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 ...
- B. Sereja and Suffixes(cf)
http://codeforces.com/problemset/problem/368/B B. Sereja and Suffixes time limit per test 1 second m ...
- Sereja and Suffixes(思维)
Sereja and Suffixes Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- Codeforces 432D Prefixes and Suffixes(KMP+dp)
题目连接:Codeforces 432D Prefixes and Suffixes 题目大意:给出一个字符串,求全部既是前缀串又是后缀串的字符串出现了几次. 解题思路:依据性质能够依据KMP算法求出 ...
- 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 ...
- codeforces 314E Sereja and Squares
discription Sereja painted n points on the plane, point number i (1 ≤ i ≤ n) has coordinates (i, 0). ...
- Codeforces 432D Prefixes and Suffixes kmp
手动转田神的大作:http://blog.csdn.net/tc_to_top/article/details/38793973 D. Prefixes and Suffixes time limit ...
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
随机推荐
- 关于ligerUi的ligertree的初始化默认选中指定项目的方法
LigerUi中ligerTree官方示例代码片段: var parm = function (data) { return data.text.indexOf('节点1.3') == 0; }; t ...
- WPF MVVM 中怎样在ViewModel总打开的对话框在窗体之前
今天在WPF的项目中,写打印插件,在ViewModel中对需要弹出打印对话框,而对话框如果没有Owner所属的时候经常会被当前应用程序遮住,导致我都不知道到底弹出来没有! 参照:http://www. ...
- osg 基本几何图元
转自:osg 基本几何图元 //osg 基本几何图元 // ogs中所有加入场景中的数据都会加入到一个Group类对象中,几何图元作为一个对象由osg::Geode类来组织管理. // 绘制几何图元对 ...
- Codeforces 616E - Sum of Remainders
616E Sum of Remainders Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + - + n mod m. As ...
- NOI 2015 T1 等式
我有 n 个式子 对于每个式子,要么是 xi = xj 的形式,要么是 xi <> xj 的形式. 现在我给出这 n 个式子,你要告诉我,这 n 个式子是否可能同时成立. [输入格式] 每 ...
- BZOJ 3997 [TJOI 2015 组合数学] 解题报告
这个题我脑洞了一个结论: 首先,我们定义满足以下条件的路径为“从右上到左下的路径”: 对于路径上任何不相同的两个点 $(x_1, y_1)$,$(x_2, y_2)$,都有: $x_1\neq x_2 ...
- hdu 3487
splay #include<cstdio> #include<cstring> #include<iostream> #include<algorithm& ...
- Javascript实现打字效果
伤感的 学期末 今天是这学期的最后一天,考完了最后一门数学,明天我们就要各自为自己的暑假打算打算了,所以趁着大家还没走一起出去打了打篮球,玩了玩轮滑,很累但是很开心,最大的感触莫过于忧伤额,明年我或许 ...
- DataTable转换List<T>集合的方法
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data; ...
- HDU3368+枚举
题意看不懂的直接看百度百科对黑白棋的解释... 做法:分情况讨论,一共8个方向. /* 搜索 */ #include<stdio.h> #include<string.h> ; ...