当前位置:网站首页>LeetCode周赛 + AcWing周赛(T4/T3)分析对比
LeetCode周赛 + AcWing周赛(T4/T3)分析对比
2022-07-05 00:57:00 【OpenAll_Zzz】
前言
两道题之间的共同点在于子数组价值的定义,LC为子数组的和乘上其长度,AcWing为子数组的和除上其长度(平均值)。
分析 - 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;
}
分析 - 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;
}
};
边栏推荐
- Daily question brushing record (13)
- IT转测试岗,从迷茫到坚定我究竟付出了什么?
- Hill sort of sorting
- uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
- abc 258 G - Triangle(bitset)
- npm install报错 强制安装
- SAP UI5 应用开发教程之一百零七 - SAP UI5 OverflowToolbar 容器控件介绍的试读版
- Which financial products with stable income are good
- 抓包整理外篇——————状态栏[ 四]
- AcWing164. 可达性统计(拓扑排序+bitset)
猜你喜欢

Deux nombres se remplacent

Learning of basic amplification circuit

Postman automatically fills headers

ORB(Oriented FAST and Rotated BRIEF)

107. Some details of SAP ui5 overflow toolbar container control and resize event processing
![[untitled]](/img/d1/85550f58ce47e3609abe838b58c79e.jpg)
[untitled]

I was beaten by the interviewer because I didn't understand the sorting

Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention

两个数相互替换

"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has
随机推荐
const、volatile和restrict的作用和用法总结
Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement
【海浪建模1】海浪建模的理论分析和matlab仿真
Hologres query management and timeout processing
npm install报错 强制安装
Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
【Unity】InputSystem
Relationship between classes and objects
Playwright recording
Hisilicon 3559 universal platform construction: YUV422 pit stepping record
每日刷题记录 (十三)
skimage: imread & imsave & imshow
107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market
【FPGA教程案例10】基于Verilog的复数乘法器设计与实现
||Interview questions you will encounter
P3304 [sdoi2013] diameter (diameter of tree)
[untitled]
有哪些收益稳定的理财产品,这两个都不错
Summary of the function and usage of const, volatile and restrict