当前位置:网站首页>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;
}
};
边栏推荐
- Distributed base theory
- Single step debugging of master data reading of SAP commerce cloud products
- URLs and URIs
- 全栈开发提效神器——ApiFox(Postman + Swagger + Mock + JMeter)
- 两个数相互替换
- TS快速入门-函数
- URL和URI
- 有哪些收益稳定的理财产品,这两个都不错
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
- [circuit design] optocoupler use and circuit design summary
猜你喜欢

资深测试/开发程序员写下无bug?资历(枷锁)不要惧怕错误......

Visual explanation of Newton iteration method

npm install报错 强制安装

107. Some details of SAP ui5 overflow toolbar container control and resize event processing
![[pure tone hearing test] pure tone hearing test system based on MATLAB](/img/1c/62ed6b3eb27a4dff976c4a2700a850.png)
[pure tone hearing test] pure tone hearing test system based on MATLAB

测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...

Oracle case: SMON rollback exception causes instance crash

107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍

2022.07.03(LC_6108_解密消息)

Innovation leads the direction. Huawei Smart Life launches new products in the whole scene
随机推荐
leetcode494,474
Single step debugging of master data reading of SAP commerce cloud products
Implementation steps of master detail detail layout mode of SAP ui5 application
Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention
Postman automatically fills headers
Mongodb series learning notes tutorial summary
Daily question brushing record (13)
有哪些收益稳定的理财产品,这两个都不错
创新引领方向 华为智慧生活全场景新品齐发
Daily practice (18): stack containing min function
2022.07.03 (LC 6109 number of people who know secrets)
Two numbers replace each other
Pycharm professional download and installation tutorial
AcWing164. 可达性统计(拓扑排序+bitset)
抓包整理外篇——————状态栏[ 四]
Safety learning week4
P4408 [noi2003] truant children (tree diameter)
Parameter passing mechanism of member methods
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
7. Scala process control