当前位置:网站首页>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;
}
};
边栏推荐
- AcWing164. 可达性统计(拓扑排序+bitset)
- SAP ui5 application development tutorial 106 - how to improve the readability of SAP ui5 application routing URL trial version
- Introduction to the gtid mode of MySQL master-slave replication
- Binary conversion problem
- What if the programmer's SQL data script coding ability is weak and Bi can't do it?
- ||Interview questions you will encounter
- The difference between string STR and new string
- [untitled]
- 多模输入事件分发机制详解
- (script) one click deployment of any version of redis - the way to build a dream
猜你喜欢
Oracle case: SMON rollback exception causes instance crash
P3304 [sdoi2013] diameter (diameter of tree)
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
多模输入事件分发机制详解
分布式BASE理论
FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market
每日刷题记录 (十三)
Binary conversion problem
兩個數相互替換
Parameter passing mechanism of member methods
随机推荐
6. Scala operator
What did I pay for it transfer to testing post from confusion to firmness?
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
POAP:NFT的采用入口?
程序员SQL数据脚本编码能力弱,BI做不出来怎么办?
lambda expressions
[selenium automation] common notes
有哪些收益稳定的理财产品,这两个都不错
多模输入事件分发机制详解
Operator explanation
npm install报错 强制安装
Hill sort of sorting
[STM32] (I) overview and GPIO introduction
Several simplified forms of lambda expression
Daily practice (18): stack containing min function
IT转测试岗,从迷茫到坚定我究竟付出了什么?
Playwright之录制
那些一门心思研究自动化测试的人,最后都怎样了?
SAP ui5 application development tutorial 106 - how to improve the readability of SAP ui5 application routing URL trial version
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!