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 ...
随机推荐
- Linux命令之文本处理(二)
cut命令 cut命令用来操作文件的列,能够视为列编辑器:与之相应是大多数的行"编辑器".如sed.grep.sort等,它们操作文本时,以行为单位. cut的主要功能就是输出文本 ...
- 从PCI上读取数据 线程和定时器效率
从PCI上读取数据 线程和定时器效率 线程: mythread=AfxBeginThread(StartContinuous,(LPVOID)1,THREAD_PRIORITY_NORMAL,0,CR ...
- poj 3250 Bad Hair Day (单调栈)
Bad Hair Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14883 Accepted: 4940 Des ...
- hadoop的一些名词解释
在网上收集了一些mapreduce中常用的一些名词的解释,分享一下: Shuffle(洗牌):当第一个map任务完成后,节点可能还要继续执行更多的map 任务,但这时候也开始把map任务的中间输出交换 ...
- URAL 1728. Curse on Team.GOV(STL set)
题目链接:space=1&num=1728" target="_blank">http://acm.timus.ru/problem.aspx?space= ...
- Java笔试题1
1. 下面的代码执行后,什么结果输出是? String s1 = new String("Test"); String s2 = new String("Test&quo ...
- 移植 libuv 至 Visual C++ 6.0 并支持 Windows XP 编译系统
移植版本 libuv:https://github.com/liigo/libuv-vc6 (支持VC6和XP.作者Liigo). 我从一年前(大概2013年6,7月份)開始在业余时间做这项移植工作, ...
- C# Windows Phone 8 WP8 开发,将WebClient的DownloadStringCompleted事件改成非同步的awiat方法。
原文:C# Windows Phone 8 WP8 开发,将WebClient的DownloadStringCompleted事件改成非同步的awiat方法. 一般我们在撰写Windows Phone ...
- J2SE习题(2)
第四.五周练习题 1.a. Define a class called BlogEntry that could be used to store an entry for a Weblog. Th ...
- nodeValue的兼容问题
nodeValue获取Text或Comment元素的文本值. 在IE6.IE7.IE8中游览器会自作聪明的去掉前面的空白字符text,而其它现代游览器则会保留空白 <body> <s ...