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 ...
随机推荐
- lightoj1030(期望dp)
有n个格子,初始的时候pos=1,然后丢骰子,然后新的pos为pos+骰子的点数,走到新的pos,可以捡走该pos上的黄金. 特殊的是,如果新的pos超过了n,那么是不会走的,要重新丢骰子. 所以要分 ...
- 微软 Build 2016
微软 Build 2016年开发者大会发布多项功能升级 微软Build 2016开发者大会在美国旧金山的莫斯康展览中心开幕.本次大会对一些重点功能进行了完善.如手写笔支持技术Windows Ink.语 ...
- Codeforces Round #198 (Div. 2) C. Tourist Problem (数学+dp)
C. Tourist Problem time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- .NET 使用 MySql.Data.dll 动态库操作MySql的帮助类--MySqlHelper
.NET 使用 MySql.Data.dll 动态库操作MySql的帮助类--MySqlHelper 參考演示样例代码,例如以下所看到的: /// <summary> /// MySql ...
- HDU5086Revenge of Segment Tree(数论)
HDU5086Revenge of Segment Tree(数论) pid=5086" target="_blank" style="">题目 ...
- cisco(思科)交换机配置篇【两】
上一页大家津津乐道cisco基本操作命令开关,而端午假期,该cisco简单的开关配置,并希望请您分享"端午节快乐"!Ok,配置交换机,首先,你必须进入全局配置模式Switch,在成 ...
- UVA 10831 - Gerg's Cake(数论)
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: ...
- BZOJ 3747 POI2015 Kinoman 段树
标题效果:有m点,每个点都有一个权值.现在我们有这个m为点的长度n该序列,寻求区间,它仅出现一次在正确的点区间内值和最大 想了很久,甚至神标题,奔说是水的问题--我醉了 枚举左点 对于每个请求留点右键 ...
- hadoop-1.1.2 在Windows环境下的部署
1:先安装Cygwin 参考http://blog.csdn.net/wind520/article/details/9223003 2:下载 3:解压在C:\cygwin\hadoop1 4:配置 ...
- sails中文文档地址
http://sailsdoc.swift.ren/ Sails.js是一个Web框架,可以于轻松构建自定义,企业级Node.js Apps.它在设计上类似于像Ruby on Rails的MVC架构的 ...