先找相邻差值的最大,第二大,第三大 删去端点会减少一个值, 删去其余点会减少两个值,新增一个值,所以新增和现存的最大的值比较一下取最大即可 #include <iostream> #include <cstdio> #include <cmath> using namespace std; #define LL long long ; int t, n, p1, p2, p3; LL a[N]; LL s1[N], s2[N]; LL sum; int main() {…
若 [i, j] 满足, 则 [i, j+1], [i, j+2]...[i,n]均满足 故设当前区间里个数为size, 对于每个 i ,找到刚满足 size == k 的 [i, j], ans += n - j + 1 . i++ 的时候看看需不需要size-- 就可以更新了. #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define LL long l…
NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the Retired Dog, has returned back to prepare for the National Higher Education Entrance Examination! In math class, NanoApe picked up sequences once aga…
传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others) Total Submission(s): 1323    Accepted Submission(s): 521 Description NanoApe, the Retired Dog, has returned back to prepare for the Natio…
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination! In math class, NanoApe picked up sequences on…
题意:给出一个序列,问能找出多少个连续的子序列,使得这个子序列中第k大的数字不小于m. 分析:这个子序列中只要大于等于m的个数大于等于k个即可.那么,我们可以用尺取法写,代码不难写,但是有些小细节需要注意(见代码注释).我觉得,<挑战程序设计>里的尺取法的内容需要好好的再回顾一下= =. 代码如下: #include <stdio.h> #include <algorithm> #include <string.h> using namespace std;…
题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的相邻两数的差的绝对值的最大值,求这些n个最大值的总和. 题解:把n=3的情况单独拿出来直接算出来,就是abs(data[3]-data[2])+abs(data[2]-data[1])+abs(data[3]-data[1]),然后讨论n>=4的情况.首先遍历求出原始数列的相邻两数的差的绝对值的最大值m…
Operation the Sequence                                                                     Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                                                            …
处理出每个位置左边的最大值和右边的最大值.然后就可以o(1)计算去掉某位置的最大值了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #includ…
King's Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 736    Accepted Submission(s): 539 Problem Description It is the king's birthday before the military parade . The ministers prepared a…
题目大意:给一个整数序列,统计<k,m>子序列的数目.<k,m>序列是满足第k大的数字不比m小的连续子序列. 题目分析:维护一个不小于m的数的个数的后缀和数组,可以枚举序列起点,二分查找右端点序列最近的一个<k,m>序列.因为最近右端点是不减的,所以也可以用two-pointer在O(n)的时间复杂度内得到结果. 代码如下: 使用二分查找: # include<iostream> # include<cstdio> # include<st…
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> #include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define ll l…
传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 1585    Accepted Submission(s): 688 Description NanoApe, the Retired Dog, has returned back to prepare for for the…
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 52 Problem Description A topological sort or topological ordering of a directed…
题目链接:pid=5228">ZCC loves straight flush pid=5228">题面: pid=5228"> ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 827    Accepted Submission(s): 340…
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出,选择跳过的题,简称想法题. 首先考虑区间的更新方法:区间左端l不动,右端r滑动, 滑到有k个数>=m时,此区间符合条件,并且发现右端点再往右滑到底,此条件一直符合(因为若加入的数小于“第K大的数”,则毫无影响.若不然,加入该数会产生一个新的第k大数,保证>=“第K大的数”>=m) 所以一找…
将大于等于m的数改为1,其余的改为0.问题转变成了有多少个区间的区间和>=k.可以枚举起点,二分第一个终点 或者尺取法. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #includ…
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i query current value of a[i], this operator will have at most 50. 解题思路: 因为给定n和m都是100000,我们每一步都做具体的操作,时间将是O(n*m),肯定超时.最开始的时候 我怎么想都不知道怎么解决.以为是线段树.比赛完了以后,看了解…
http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:给出 a,b,n,递推出 f(n) = f(n-1) + f(n-2) * 2 + n ^ 4. f(1) = a, f(2) = b. 思路:在比赛时候知道是矩阵快速幂,可是推不出矩阵.那个n^4不知道怎么解决.结束后问其他人才知道要构造一个7 * 7的矩阵,而不是3 * 3的.. 转自:http://blog.csdn.net/spring371327/article/details/5297…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5274 [题目大意] 给出一棵树,每个点有一个权值,权值可修改,且大于等于0,询问链上出现次数为奇数的数,题目保证每次询问的链上最多只有一个数出现次数为奇数.如果不存在这样的数,就输出-1. [题解] 题目等价于求链上点的异或和,树链剖分,线段树维护区间异或和,然后链上查询即可,注意到存在权值为0的特殊情况,所以我们将更新的数字都+1,在最后处理答案的时候-1即可. [代码] #include <…
http://acm.hdu.edu.cn/showproblem.php?pid=6305 题目 对于A,B两个序列,任意的l,r,如果RMQ(A,l,r)=RMQ(B,l,r),B序列里的数为[0,1]的实数,B的重量为B的所有元素的和,否则为0.问你B的期望重量是多少. 分析 准备知识:笛卡尔树https://skywt.cn/posts/cartesian-tree/ RMQ-Similar实际上就是A和B的笛卡尔树一样.于是这个题就是笛卡尔树同构的问题,假设A的笛卡尔树的子树大小为sz…
CA Loves Palindromic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 301    Accepted Submission(s): 131 Problem Description CA loves strings, especially loves the palindrome strings. One day…
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hates those numbers which can be written as a^b (a, b are positive integers,2<=b<=r),so he removed them all.Yellowstar calls the sequence that formed by…
There is a sequence aa of length nn. We use aiai to denote the ii-th element in this sequence. You should do the following three types of operations to this sequence. 0 x y t0 x y t: For every x≤i≤yx≤i≤y, we use min(ai,t)min(ai,t) to replace the orig…
Price List 题意: 有n件商品,每天只能买一件,并且会记录账本,问有多少次一定记多了? 题解: 就是求和,最后如果大于和就输出1,否则0. 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; #define SI(N) cin>>(N) #define SII(N,M) cin>>(N)>>(M) #define rep(i,b) for(int i=0;i…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 339    Accepted Submission(s): 165 Problem Description NanoApe, the Retired Dog, has returned back to prepare for…
NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) Problem Description NanoApe, the Retired Dog, has returned back to prepare for the National Higher Education Entr…
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/131072 K (Java/Others) Problem Description NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examinatio…
题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/131072 K (Java/Others) Problem Description NanoApe, the Retired Dog, has returned back to prepare for the National Higher Education Entrance Examination! In…