Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 503    Accepted Submission(s): 256 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fr…
维护一个递增的和递减的单调队列 Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 78    Accepted Submission(s): 40 Problem Description Tom owns a company and he is the boss. There are n staffs which a…
题意:给T足数据,然后每组一个n和k,表示n个数,k表示最大同意的能力差,接下来n个数表示n个人的能力,求能力差在k之内的区间有几个 分析:维护一个区间的最大值和最小值,使得他们的差小于k,于是採用单调队列 普通单调队列做法: #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 1e6+5; i…
题意:给出一个数列.问当中存在多少连续子区间,当中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解.终于解即为dp[n]. 此外 如果对于arr[i] 往左遍历 一直到arr[r] 此时从区间r到区间i满足(最大值-最小值)<k,再往左一位即越界 或者 不满足条件,此时有 dp[i] = dp[i-1] + i - r + 1; 由于数据量大 往左遍历时 可能会超时 ,所以用rmq打表 查找r时用二分 就过了 代码: #include <algorithm…
Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 557    Accepted Submission(s): 280 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fr…
Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 148    Accepted Submission(s): 71 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered fro…
题目链接: Assignment  题意: 给出一个数列,问其中存在多少连续子序列,使得子序列的最大值-最小值<k. 题解: RMQ先处理出每个区间的最大值和最小值(复杂度为:n×logn),相当于求出了每个区间的最大值-最小值.那么现在我们枚举左端点,二分右端点就可以在n×logn×logn的时间内过. #include<bits/stdc++.h> using namespace std; ; int vec[MAX_N]; ]; ]; ; int N,M,T; void ST(in…
题意:有一个n * n的网格,每个网格中间有一颗树,你知道每棵树的高,你可以选择一个矩形区域把里面的树都围起来,但是矩形区域里面任意两棵树的高度差的绝对值不超过m,问这个矩形的最大面积是多少? 思路:前两天的牛客多校有一个最大子矩形问题,当时用的扫描线 + 单调栈过的,结果场上想了半天灭结果QAQ.这个题有限制条件就不好那么做.注意到题目中的信息,可以用O(n ^ 3)的算法做,如果我们枚举矩阵的左上角和右下角是O(n ^ 4),而且没什么优化手段,不行.但是我们转化一下思路,我们枚举矩形的上边…
Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to some staffs who were in the same group. In a group, the difference…
Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to some staffs who were in the same group. In a gr…