当前位置:网站首页>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;
}
};
边栏推荐
- 初识ROS
- 华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
- User login function: simple but difficult
- Check if this is null - checking if this is null
- Visual explanation of Newton iteration method
- Playwright之录制
- SAP UI5 应用开发教程之一百零七 - SAP UI5 OverflowToolbar 容器控件介绍的试读版
- Operator explanation
- 创新引领方向 华为智慧生活全场景新品齐发
- The most complete regular practical guide of the whole network. You're welcome to take it away
猜你喜欢
"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has
Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...
User login function: simple but difficult
lambda expressions
Basic concept and usage of redis
What if the programmer's SQL data script coding ability is weak and Bi can't do it?
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
全栈开发提效神器——ApiFox(Postman + Swagger + Mock + JMeter)
随机推荐
[Yocto RM]11 - Features
《论文笔记》Multi-UAV Collaborative Monocular SLAM
7. Scala process control
Upload avatar on uniapp
Kibana index, mapping, document operation
2022.07.03 (LC 6109 number of people who know secrets)
107. Some details of SAP ui5 overflow toolbar container control and resize event processing
Les phénomènes de « salaire inversé » et de « remplacement des diplômés » indiquent que l'industrie des tests a...
BGP comprehensive experiment
SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
创新引领方向 华为智慧生活全场景新品齐发
P3304 [sdoi2013] diameter (diameter of tree)
程序员SQL数据脚本编码能力弱,BI做不出来怎么办?
[Yocto RM]10 - Images
Check if this is null - checking if this is null
AcWing164. 可达性统计(拓扑排序+bitset)
Oracle case: SMON rollback exception causes instance crash
FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market
[circuit design] optocoupler use and circuit design summary
(script) one click deployment of any version of redis - the way to build a dream