主题链接:http://115.28.76.232/problem?

pid=1427

Nice Sequence

Time Limit: 12000/6000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

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

      The first line of the input file contains n and k (1 ≤ n ≤ 200 000, 0 ≤ k ≤ 200 000). The second line contains n integer numbers ranging from 0 to n.

Output

      Output the greatest l such that the sequence a1, a2,..., al is
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

Andrew Stankevich Contest 23

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的更多相关文章

  1. ACdream 1427—— Nice Sequence——————【线段树单点更新,区间查询】

    Nice Sequence Time Limit: 4000/2000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) Su ...

  2. acd - 1427 - Nice Sequence(线段树)

    题意:一个由n个数组成的序列(序列元素的范围是[0, n]).求最长前缀 j .使得在这个前缀 j 中对于随意的数 i1 < i2.都满足随意的 m <= j.i1 在前 m 个数里出现的 ...

  3. 课程五(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 ...

  4. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  5. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  6. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  7. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  8. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  9. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

随机推荐

  1. 无法打开登录所请求的数据库 "ASPState"。登录失败。 用户 'NT AUTHORITY/SYSTEM' 登录失败。

    原文:无法打开登录所请求的数据库 "ASPState".登录失败. 用户 'NT AUTHORITY/SYSTEM' 登录失败. 无法打开登录 'ASPState' 中请求的数据库 ...

  2. java移位运算符具体解释

    java移位运算符不外乎就这三种:<<(左移).>>(带符号右移)和>>>(无符号右移). 1. 左移运算符 左移运算符<<使指定值的全部位都左移 ...

  3. 高速幂 POW优化

    #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  4. 谁的用户在世界上是&#160;&#160;明基决心保时捷设计标准

        谈到保时捷.相信非常多人都非常了解,世界名车啊,仅仅有高富帅才玩儿得起.只是,假设由保时捷的设计师来设计一款显示器,水准一流.质地厚道,且价格亲民,你怎么看?     如近期京东上热销的明基G ...

  5. HTML contact form with CAPTCHA

    http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html#codedownload

  6. PM俱乐部之旅7-弱活着

     有些人认为,最终我们放松一点时间,有意想不到的事情发生--公司组织结构调整. 公司由于业务范围调整,所以要进行对应的组织结构调整.PMO部门也随之重组,项目经理俱乐部的活动改成项目交流会,请项目 ...

  7. SICP的一些个人看法

    网上搜书的时候,看到非常多人将这本书神话. 坦率地说,个人认为这本书过于学术化, 没什么实际project价值.一大堆题目也基本是高中数学竞赛题类似,浪费时间. 软件的核心技术是什么? 1>   ...

  8. 无法识别的属性“targetFramework”。请注意,属性名是大写和小写。错误的解决方案

    "/CRM"应用server错. 配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查以下的特定错误具体信息并适当地改动配置文件. 分析器错误消息: 无法识别的属性 ...

  9. 【原创】leetCodeOj --- Excel Sheet Column Title 解题报告

    题目地址: https://oj.leetcode.com/problems/excel-sheet-column-title/ 题目内容: Given a positive integer, ret ...

  10. HDU1237 简单的计算器 【堆】+【逆波兰式】

    简单的计算器 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...