Subsequence(hdu3530)
Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6141 Accepted Submission(s): 2041
For each test case, the first line has three integers, n, m and k. n is the length of the sequence and is in the range [1, 100000]. m and k are in the range [0, 1000000]. The second line has n integers, which are all in the range [0, 1000000].
Proceed to the end of file.
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<queue>
7 #include<stack>
8 using namespace std;
9 typedef long long LL;
10 int ask[100005];
11 int cnt[100005];
12 struct node1
13 {
14 int x;
15 int id;
16 bool operator<(const node1 &cx)const
17 {
18 if(cx.x == x)
19 return cx.id<id;
20 else return cx.x>x;
21 }
22 };
23 struct node2
24 {
25 int x;
26 int id;
27 bool operator<(const node2 &cx)const
28 {
29 if(cx.x == x)
30 return cx.id<id;
31 else return cx.x<x;
32 }
33 };
34 priority_queue<node1>que1;
35 priority_queue<node2>que2;
36 int main(void)
37 {
38 int n,m,k;
39 while(scanf("%d %d %d",&n,&m,&k)!=EOF)
40 {
41 while(!que1.empty())que1.pop();
42 while(!que2.empty())que2.pop();
43 int i,j;
44 for(i = 0; i < n; i++)
45 {
46 scanf("%d",&ask[i]);
47 }
48 int l = 0;
49 int r = 0;
50 int cc = 0;
51 int ma = ask[0];
52 int mi = ask[0];
53 int x = abs(ma-mi);
54 if(x <= k&&x >= m)cc = 1;
55 node1 ak;
56 node2 ap;
57 ak.x =ask[0];
58 ak.id = 0;
59 ap.x = ask[0];
60 ap.id = 0;
61 que1.push(ak);
62 que2.push(ap);
63 while(l<=r&&r<n)
64 {
65 while(x <= k &&r < n-1)
66 {
67 r++;
68 int c = abs(ask[r]-ma);
69 c = max(abs(ask[r]-mi),c);
70 if(c > k)
71 { //printf("%d %d\n",l,r);
72 r--;
73 break;
74 }
75 node1 ac;
76 ac.x = ask[r];
77 ac.id = r;
78 node2 bc;
79 bc.x= ask[r];
80 bc.id = r;
81 que1.push(ac);
82 que2.push(bc);
83 if(ask[r] > ma)
84 {
85 ma = ask[r];
86 }
87 else if(ask[r] < mi)
88 {
89 mi = ask[r];
90 }
91 x = abs(ma-mi);//printf("%d\n",x);
92 }
93 if(x >= m)
94 {
95 cc = max(cc,r-l+1);
96 }
97 if(ask[l] == ma)
98 {
99 while(!que1.empty())
100 {
101 node1 acc = que1.top();
102 if(acc.id <= l)
103 {
104 que1.pop();
105 }
106 else
107 {
108 ma = acc.x;
109 break;
110 }
111 }
112 }
113 if(ask[l]==mi)
114 {
115 while(!que2.empty())
116 {
117 node2 acc = que2.top();
118 if(acc.id <= l)
119 {
120 que2.pop();
121 }
122 else
123 {
124 mi = acc.x;
125 break;
126 }
127 }
128 }
129 l++;
130 if(l == r+1)
131 { //printf("%d\n",r);
132 r++;
133 node1 akk;
134 node2 app;
135 akk.x =ask[r];
136 akk.id = r;
137 app.x = ask[r];
138 app.id = r;
139 que1.push(akk);
140 que2.push(app);
141 mi = ask[r];
142 ma = ask[r];
143 }
144 }
145 printf("%d\n",cc);
146 }
147 return 0;
148 }
Subsequence(hdu3530)的更多相关文章
- HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)
Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- Poj 2533 Longest Ordered Subsequence(LIS)
一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- 1423 Greatest Common Increasing Subsequence (LCIS)
讲解摘自百度; 最长公共上升子序列(LCIS)的O(n^2)算法? 预备知识:动态规划的基本思想,LCS,LIS.? 问题:字符串a,字符串b,求a和b的LCIS(最长公共上升子序列).? 首先我们可 ...
- Subsequence(HDU3530+单调队列)
题目链接 传送门 题面 题意 找到最长的一个区间,使得这个区间内的最大值减最小值在\([m,k]\)中. 思路 我们用两个单调队列分别维护最大值和最小值,我们记作\(q1\)和\(q2\). 如果\( ...
- POJ 2533-Longest Ordered Subsequence(DP)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 34454 Acc ...
- HPU第三次积分赛-D:Longest Increasing Subsequence(DP)
Longest Increasing Subsequence 描述 给出一组长度为n的序列,a1,a2,a3,a4...an, 求出这个序列长度为k的严格递增子序列的个数 输入 第一行输入T ...
- HDU 1423 Greatest Common Increasing Subsequence(LCIS)
Greatest Common Increasing Subsequenc Problem Description This is a problem from ZOJ 2432.To make it ...
- Longest common subsequence(LCS)
问题 说明该问题在生物学中的实际意义 Biological applications often need to compare the DNA of two (or more) different ...
- 第六周 Leetcode 446. Arithmetic Slices II - Subsequence (HARD)
Leetcode443 题意:给一个长度1000内的整数数列,求有多少个等差的子数列. 如 [2,4,6,8,10]有7个等差子数列. 想了一个O(n^2logn)的DP算法 DP[i][j]为 对于 ...
随机推荐
- C++类虚函数内存分布(这个 你必须懂)
转自:http://www.cnblogs.com/jerry19880126/p/3616999.html C++类内存分布 书上类继承相关章节到这里就结束了,这里不妨说下C++内存分布结构,我们来 ...
- 【leetcode】451. Sort Characters By Frequency
Given a string s, sort it in decreasing order based on the frequency of the characters. The frequenc ...
- innodb和myisam对比及索引原理区别
InnoDB和MyISAM是很多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,5.7之后就不一样了 1.事务和外键 InnoDB具有事务,支持4个事务隔离级别,回滚,崩溃修复能力和多版 ...
- java加密方式
加密,是以某种特殊的算法改变原有的信息数据,使得未授权的用户即使获得了已加密的信息,但因不知解密的方法,仍然无法了解信息的内容.大体上分为双向加密和单向加密,而双向加密又分为对称加密和非对称加密(有些 ...
- 接口测试 python+PyCharm 环境搭建
1.配置Python环境变量 a:我的电脑->属性->高级系统设置->环境变量->系统变量中的PATH变量. 变量名:PATH 修改变量值为:;C:\Python27 ...
- Linux:cut命令...未完待续
一.定义 正如其名,cut的工作就是"剪",具体的说就是在文件中负责剪切数据用的.cut是以每一行为一个处理对象的,这种机制和sed是一样的. 2.剪切依据 cut命令主要是接受三 ...
- Type of 'this' pointer in C++
In C++, this pointer is passed as a hidden argument to all non-static member function calls. The typ ...
- navicat突然连接不上远程linux服务器上的mysql
我linux服务器上的mysql是docker安装的,突然有一天我的navicat连接不上服务器上的mysql,于是开始了下面一系列的修复 1.首先登录服务器上mysql,看是否能正常登录,我发现不能 ...
- 用Navicat连接数据库-数据库连接(MySQL演示)
用Navicat连接数据库-数据库连接(MySql演示) 已成功连接,连接方式步骤如下: 开始之前首先准备连接信息: [ 一般你可以自己去配置文件中找 或者 问连接过该数据库的人/所有者(负责人/同学 ...
- centos7部署二进制mysql-5.6
目录 一.环境声明 二.程序部署 一.环境声明 [mysql-Server] 主机名 = host-1 系统 = centos-7.3 地址 = 1.1.1.1 软件 = mysql-5.6.39 3 ...