ACdream 1427 Nice Sequence
主题链接:http://115.28.76.232/problem?
pid=1427
Nice Sequence
Problem Description
Let us consider the sequence a1, a2,..., an of
non-negative integer numbers. Denote as ci,j the number of occurrences of the number i among a1,a2,..., aj.
We call the sequence k-nice if for all i1<i2 and
for all j the following condition is satisfied: ci1,j ≥ ci2,j −k.
Given the sequence a1,a2,..., an and
the number k, find its longest prefix that is k-nice.
Input
Output
k-nice.
Sample Input
10 1
0 1 1 0 2 2 1 2 2 3
2 0
1 0
Sample Output
8
0
Source
Manager
用线段树维护 0到A[i]-1间的最小值。用F[A[i]] 统计频率。推断 0 到 A[i]-1范围内的最小值与F[A[i]]-K的大小就可以。
//#pragma comment(linker, "/STACK:36777216")
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#define LL long long
#define MAXN 200100
struct Node{
int left,right,v;
};Node Tree[MAXN<<2];
void Build(int id,int left,int right){
Tree[id].v=0;
Tree[id].left=left;
Tree[id].right=right;
if(left==right) return;
int mid=(left+right)>>1;
Build(id<<1,left,mid);
Build(id<<1|1,mid+1,right);
}
void Update(int id,int pos,int add){
int left=Tree[id].left,right=Tree[id].right;
if(left==right){
Tree[id].v+=add;
return;
}
int mid=(left+right)>>1;
if(mid>=pos)
Update(id<<1,pos,add);
else
Update(id<<1|1,pos,add);
Tree[id].v=min(Tree[id<<1].v,Tree[id<<1|1].v);
}
int Query(int id,int Qleft,int Qright){
int left=Tree[id].left,right=Tree[id].right;
if(left>=Qleft && right<=Qright)
return Tree[id].v;
int mid=(left+right)>>1;
if(mid>=Qright)
return Query(id<<1,Qleft,Qright);
else if(mid<Qleft)
return Query(id<<1|1,Qleft,Qright);
int r1=Query(id<<1,Qleft,Qright),r2=Query(id<<1|1,Qleft,Qright);
return min(r1,r2);;
}
int A[MAXN];
int F[MAXN];
int main(){
int N,K;
while(~scanf("%d%d",&N,&K)){
for(int i=1;i<=N;i++)
scanf("%d",&A[i]);
Build(1,0,N);
memset(F,0,sizeof(F));
int i;
for(i=1;i<=N;i++){
F[A[i]]++;
Update(1,A[i],1);
if(A[i]==0) continue;
int ans=Query(1,0,A[i]-1);
if(ans<F[A[i]]-K) break;
}
printf("%d\n",i-1);
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
ACdream 1427 Nice Sequence的更多相关文章
- ACdream 1427—— Nice Sequence——————【线段树单点更新,区间查询】
Nice Sequence Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...
- acd - 1427 - Nice Sequence(线段树)
题意:一个由n个数组成的序列(序列元素的范围是[0, n]).求最长前缀 j .使得在这个前缀 j 中对于随意的数 i1 < i2.都满足随意的 m <= j.i1 在前 m 个数里出现的 ...
- 课程五(Sequence Models),第一 周(Recurrent Neural Networks) —— 3.Programming assignments:Jazz improvisation with LSTM
Improvise a Jazz Solo with an LSTM Network Welcome to your final programming assignment of this week ...
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
随机推荐
- 移动web性能优化笔记
移动web性能优化 最近看了一些文章,对移动web性能优化方法,做一个简单笔记 笔记内容主要出自 移动H5前端性能优化指南和移动前端系列——移动页面性能优化
- phpcms v9框架的目录结构分析
phpcms v9框架的目录结构分析: 了解v9框架的目录结构,有助于帮助我们快速建立起对v9框架的一个整体认识 打开"mycms"项目,有如下文件和目录 使用 ...
- Windows Phone开发(36):动画之DoubleAnimation
原文:Windows Phone开发(36):动画之DoubleAnimation 从本节开始,我们将围绕一个有趣的话题展开讨论--动画. 看到动画一词,你一定想到Flash,毕竟WP应用的一个很重要 ...
- json级联城市
代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> < ...
- 重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree
原文:重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree [源码下载] 重新想象 ...
- HDU 3681 BFS&像缩进DP&二分法
N*M矩阵.从F出发点.走完全部Y点.每个人格开支1电源点,去G点,电池充满,D无法访问.最小的开始问什么时候满负荷可以去完全部Y.Y和G总共高达15一 第一BFS所有的F.Y.G之间的最短距离. 然 ...
- Cocos2d-x学习笔记(19)(TestCpp源代码分析-3)
本章主要介绍testBasic.h/cpp,这两个文件主要用于返回主场景界面. //testBasic.h #ifndef _TEST_BASIC_H_ #define _TEST_BASIC_H_ ...
- Linux高性能server规划——多进程编程
多进程编程 多进程编程包含例如以下内容: 复制进程影映像的fork系统调用和替换进程映像的exec系列系统调用. 僵尸进程以及怎样避免僵尸进程 进程间通信(Inter-Process Communic ...
- Solr在结果返回函数值
如果你有一个服务,你的用户能够搜索不同的公司.用户输入一个简单的keyword,能够返回匹配keyword的公司,可是有一天,用户要求返回的公司列表中能够显示公司跟用户的距离,这是该怎么做呢? 1.如 ...
- java通讯录
)设一个通信录由以下几项数据信息构成: 数据项 类型 姓名 字符串 地址 字符串 邮政编码 ...