HDU 5289 - Assignment http://acm.hdu.edu.cn/showproblem.php?pid=5289 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 t…
题意: 给一个整数序列,多达10万个,问:有多少个区间满足“区间最大元素与最小元素之差不超过k”.k是给定的. 思路: 如果穷举,有O(n*n)复杂度.可以用ST算法先预处理每个区间最大和最小,O(nlogn).再扫一遍整个序列,两个指针L,R用于这样判断:如果A[L,R]这个区间满足要求,则R++,否则统计ans+=R-L,且l++.因为在[L,R]这个区间是满足要求的,那么以L开头的,[L,L].[L,L+1]...[L,R-1]就都是满足要求的,刚好R-L个. #include <bits…
题目链接:pid=5289">http://acm.hdu.edu.cn/showproblem.php?pid=5289 题面: Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 672    Accepted Submission(s): 335 Problem Description Tom owns a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5289 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 tas…
Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3813    Accepted Submission(s): 1771 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered…
题目链接:HDU 5443 Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with \(a_1,a_2,a_3,...,a_n\) representing the size of the water source. Give…
[题目链接]click here~~ [题目大意]: 给出一个数列,问当中存在多少连续子序列,子序列的最大值-最小值<k [思路]:枚举数列左端点.然后二分枚举右端点,用ST算法求区间最值.(或用单调队列的思路) 代码: #include <bits/stdc++.h> using namespace std; const int N=1e5+10; typedef long long LL; #define Max(a,b) a>b?a:b #define Min(a,b) a&…
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…
Assignment 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5289 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…
题意:求一段长度为n的序列里有多少个子区间内的最大值减最小值小于k. 解法:RMQ+尺取法或单调队列.RMQ可以用st或者线段树,尺取法以前貌似YY出来过……只是不知道是这个东西…… 设两个标记l和r,对于区间[l, r]如果满足题中条件则ans+=(r - l + 1),然后r右移一位,直到不符合条件,将l左移,直到符合条件. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include&l…