Subarrays
C1. Good Subarrays (Easy Version)
思路:我们枚举每一个左端点,对于每一个左端点,寻找最长的满足条件的区间,这个区间长度就是左端点对答案的贡献,可以发现具有单调性,右端点只会前进不会倒退。所以我们两个指针各扫一遍区间就可以。 #include <bits/stdc++.h> #define ls p<<1 #define rs p<< ......
C1. Good Subarrays (Easy Version)(推公式找性质)
思路: \[能想到平方是比较特殊的,因为x*x一定是x的倍数也就是说\sqrt[2]{x*x} = {x} \]\[所以需要考虑平法之间的数手模一下样例可以发现 [x^2 ,(x+1)^2)之间是x倍数的有x^2 \]\[x*(x+1), x*(x+2)这三个,所以可以知道平方之间有三个,只要讨论一 ......
[LeetCode] 1630. Arithmetic Subarrays
A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the s ......
[USACO23FEB] Equal Sum Subarrays G 题解
[USACO23FEB] Equal Sum Subarrays G 题解 题目链接 \(O(n^5)\) 暴力 显然,如果修改 \(a_i\) 的值,只会影响包含 \(a_i\) 的区间的区间和。于是对于每个 \(a_i\),可以将所有区间分成两类,即包含 \(a_i\) 的区间和不包含 \(a_ ......
[LeetCode] 2863. Maximum Length of Semi-Decreasing Subarrays_Medium tag: stack
You are given an integer array nums. Return the length of the longest semi-decreasing subarray of nums, and 0 if there are no such subarrays. A subarr ......
[CF1158F]Density of subarrays
F - Density of subarrays 屲,平衡复杂度题 首先考虑如何求一个序列的密度 从最左端开始,找到需序列\(A[1...n]\)的最小段\(A[1...a_1]\),使其包含\(1\sim c\)的所有颜色,然后又以\(a_1+1\)为起点,找下一个最短的包含\(1\sim c\) ......
[CF1158F] Density of subarrays
Let $ c $ be some positive integer. Let's call an array $ a_1, a_2, \ldots, a_n $ of positive integers $ c $ -array, if for all $ i $ condition $ 1 \l ......
[LeetCode] 2461. Maximum Sum of Distinct Subarrays With Length K
You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions: T ......
abc275_f Erase Subarrays 题解
# [Erase Subarrays](https://vjudge.csgrandeur.cn/problem/AtCoder-abc275_f) ## 题意 有一个长度为 $n$ 的整数序列 $a$,你可以执行以下操作若干次(可以不执行): - 选择序列的一个子段,将子段中的每个数变为 $0$。 ......
[LeetCode] 1031. Maximum Sum of Two Non-Overlapping Subarrays
Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths ......
Codeforces Educational Codeforces Round 145 (Rated for Div. 2) C. Sum on Subarrays 题解
题意 Codeforces Educational Codeforces Round 145 (Rated for Div. 2) C. Sum on Subarrays 给你 $n$ 和 $k$ ,要求生成一个长度为 $n$ 的数组 $a$,且他的非空正子数组的数量为 $k$ ,非空负子数组的数量 ......
[LeetCode] 2348. Number of Zero-Filled Subarrays
Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. ......