codeforceCodeForces - 1107G】的更多相关文章

单调栈 RMQ #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<string> #include<queue> #include<map> #include<set> #include<list> #include<ctime> #include<ctype.h> #…
咸鱼了好久...出来冒个泡_(:з」∠)_ 题目连接:1107G - Vasya and Maximum Profit 题目大意:给出\(n,a\)以及长度为\(n\)的数组\(c_i\)和长度为\(n\)的严格单调上升数组\(d_i\),求\(\max\limits_{1 \le l \le r \le n} (a\cdot(r-l+1)-\sum_{i=l}^{r}c_i-gap(l,r))\),其中\(gap(l, r) = \max\limits_{l \le i < r} (d_{i…
Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has \(n\) problems to choo…
洛谷 Codeforces 我竟然能在有生之年踩标算. 思路 首先考虑暴力:枚举左右端点直接计算. 考虑记录\(sum_x=\sum_{i=1}^x c_i\),设选\([l,r]\)时那个奇怪东西的平方为\(f(l,r)\),使劲推式子: \[ ans_{l,r}=(r-l+1)\times a-sum_r+sum_{l-1}-f(l,r)\\ ans_{l,r}+l\times a-a-sum_{l-1}=r\times a-sum_r-f(l,r)\\ ans_{l,r}+l\times…
1.答案要取连续的区间疯狂暗示线段树. 2.外层枚举r,内层枚举l显然过于暴力. 3.考虑内层的优化.dp[i]:以第i位为结尾的答案(长度大于1的).dp[i] = max(第一种情况,第二种情况).解释一下,首先我们可以做到求出i前面gap[j] > gap[i],j < i最大的j的位置pos,然后其中第一种情况为:自力更生,区间pos-i内gap[i]是最大的.这种情况可以使用线段树logn得到区间内最大右子段和:其中第二种情况为:寄人篱下,区间从pos前的某一位一直到i,即最大的ga…