当前位置:网站首页>Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
2022-07-05 00:57:00 【OpenAll_ Zzz】
AcWing 57 T3
Leetcode Biweekly 80 T4
Preface
The common ground between the two questions lies in the subarray value The definition of ,LC Multiply the sum of subarrays by their length ,AcWing Divide the sum of subarrays by their length ( Average ).
analysis - AcWing T3
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1000010;
int n;
LL s[N];
int stk[N];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
{
int x;
scanf("%d", &x);
s[i] = s[i - 1] + x - 100;
}
int top = 0,res = 0;
stk[++ top] = 0;
for(int i = 1; i <= n; i ++)
{
if(s[stk[top]] > s[i]) stk[++ top] = i;
else if(s[stk[top]] < s[i])
{
int l = 0, r = top;
while(l < r)
{
int mid = l + r >> 1;
if(s[stk[mid]] < s[i]) r = mid;
else l = mid + 1;
}
res = max(res, i - stk[r]);
}
}
printf("%d\n", res);
return 0;
}
analysis - LeetCode T4
class Solution {
public:
typedef long long LL;
long long countSubarrays(vector<int>& nums, long long k) {
LL res = 0, sum = 0;
for(int i = 0, j = 0; j < nums.size(); j ++)
{
sum += nums[j];
while(sum * (j - i + 1) >= k) sum -= nums[i ++];
res += j - i + 1;
}
return res;
}
};
边栏推荐
- 有哪些收益稳定的理财产品,这两个都不错
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
- 【C】(笔试题)指针与数组,指针
- Daily question brushing record (13)
- Open3d uses GICP to register point clouds
- Call Huawei order service to verify the purchase token interface and return connection reset
- There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
- npm install报错 强制安装
- “薪资倒挂”、“毕业生平替” 这些现象说明测试行业已经...
- The difference between string STR and new string
猜你喜欢
Distributed base theory
4. Scala writes HelloWorld in idea, in-depth analysis of accompanying objects, and association of source packages
abc 258 G - Triangle(bitset)
测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...
Oracle case: SMON rollback exception causes instance crash
leetcode518,377
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Recursive execution mechanism
那些一门心思研究自动化测试的人,最后都怎样了?
基本放大电路的学习
随机推荐
pycharm专业版下载安装教程
创新引领方向 华为智慧生活全场景新品齐发
【海浪建模3】三维随机真实海浪建模以及海浪发电机建模matlab仿真
[Yocto RM]10 - Images
Arbitrum:二维费用
I was beaten by the interviewer because I didn't understand the sorting
Check if this is null - checking if this is null
PyTorch: In-place Operation
NPM install error forced installation
What did I pay for it transfer to testing post from confusion to firmness?
Postman automatically fills headers
Safety learning week4
[circuit design] optocoupler use and circuit design summary
Poap: the adoption entrance of NFT?
abc 258 G - Triangle(bitset)
“薪資倒掛”、“畢業生平替” 這些現象說明測試行業已經...
【selenium自动化】常用注解
Several simplified forms of lambda expression
[microprocessor] VHDL development of microprocessor based on FPGA
【Unity】InputSystem