当前位置:网站首页>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;
}
};
边栏推荐
- 测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...
- Basic concept and usage of redis
- Hisilicon 3559 universal platform construction: YUV422 pit stepping record
- 【C】(笔试题)指针与数组,指针
- Get to know ROS for the first time
- I was beaten by the interviewer because I didn't understand the sorting
- 小程序直播 + 电商,想做新零售电商就用它吧!
- Pycharm professional download and installation tutorial
- [microprocessor] VHDL development of microprocessor based on FPGA
- GDB common commands
猜你喜欢

BGP comprehensive experiment

POAP:NFT的采用入口?

Hill sort of sorting

分布式BASE理论

What did I pay for it transfer to testing post from confusion to firmness?

Postman automatically fills headers

Detailed explanation of multi-mode input event distribution mechanism

Poap: the adoption entrance of NFT?

小程序直播 + 电商,想做新零售电商就用它吧!

《论文笔记》Multi-UAV Collaborative Monocular SLAM
随机推荐
6. Scala operator
《论文笔记》Multi-UAV Collaborative Monocular SLAM
2022.07.03 (LC 6109 number of people who know secrets)
7. Scala process control
Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement
Inventory of more than 17 typical security incidents in January 2022
Hill sort of sorting
[wave modeling 3] three dimensional random real wave modeling and wave generator modeling matlab simulation
TS quick start - functions
两个数相互替换
SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
有哪些收益稳定的理财产品,这两个都不错
【FPGA教程案例9】基于vivado核的时钟管理器设计与实现
What happened to those who focused on automated testing?
abc 258 G - Triangle(bitset)
2022.07.03 (lc_6111_counts the number of ways to place houses)
Kibana index, mapping, document operation
Identifiers and keywords
Paper notes multi UAV collaborative monolithic slam
Daily question brushing record (13)