当前位置:网站首页>[8.8] Code Source - [Non-falling subarray game] [Longest rising subsequence count (Bonus)] [Substring (data enhanced version)]
[8.8] Code Source - [Non-falling subarray game] [Longest rising subsequence count (Bonus)] [Substring (data enhanced version)]
2022-08-10 03:26:00 【ZhgDgE】
#886. Do not drop subarray games
题意:
题解:(分块/三分) 代码源每日一题Div1 Do not drop subarray games
思路:首先,Pick a point first,The back must be chosen L , R L,R L,R 其中的一个,This will maximize the score.Then take the subscript of the point we choose as the independent variable,Score as the dependent variable,This function is a downward convex function(不会证),Three points out the extreme point.
问题转化为,给定区间 [ l , r ] [l,r] [l,r] Ask for the fraction of this interval.We block the original sequence,Divide into several non-decreasing subintervals.A length inside the subinterval is l e n len len The fraction of the subinterval is l e n ( l e n + 1 ) 2 \frac {len(len+1)}2 2len(len+1) ,Then we preprocess the prefix sum on the block,and the number of the block where each element is preprocessed,and left border and right border.We ask for an interval [ l , r ] [l,r] [l,r] ,The score is the interval score of the whole block in the interval plus the score of the two residual blocks.
AC代码:http://oj.daimayuan.top/submission/326684
#884. Longest ascending subsequence count(Bonus)
题意:Find the number of longest ascending subsequences.区间长度 n ( 1 ≤ n ≤ 4 ⋅ 1 0 5 ) n(1\leq n\leq 4\cdot 10^5) n(1≤n≤4⋅105) .
题解:(DP/线段树/树状数组)Longest ascending subsequence count(Bonus)
思路:Can be a tree of weights segments or a tree-like array.The tree array I use.
定义 l e n ( i ) len(i) len(i) 表示以 a i a_i ai 结尾的 LIS 长度, c n t ( i ) cnt(i) cnt(i) 表示对应的 LIS 方案.转移: l e n ( i ) = 1 + max j < i , a j < a i l e n ( j ) , c n t ( i ) = ∑ j < i , l e n ( j ) + 1 = l e n ( i ) c n t ( j ) len(i)=1+\max_{j<i,a_j<a_i}len(j),cnt(i)=\sum_{j<i,len(j)+1=len(i)}cnt(j) len(i)=1+maxj<i,aj<ailen(j),cnt(i)=∑j<i,len(j)+1=len(i)cnt(j)
对于 a i a_i ai ,我们要找到 a j ( j < i , a j < a i ) a_j(j<i,a_j<a_i) aj(j<i,aj<ai) 的信息,This information can be stored in a tree-like array indexed by the range,Then query prefix information.Then we need to query the maximum value of the range prefix,and the corresponding count for the maximum value.This requires a tree-like array to maintain two-tuples.
The tree-like array maintains the prefix maximum value and the count of the prefix maximum value:
struct trie{
int n;
int tr[N], tr2[N]; // tr is the prefix maximum value, tr2 is the count of prefix maximum values
void init(int n){
this -> n = n;
rep(i, 0, n) tr[i] = tr2[i] = 0;
}
void add(int x, int k, int c){
for(int i = x; i <= n; i += i & -i){
if(tr[i] < k) tr[i] = k, tr2[i] = c;
else if(tr[i] == k) tr2[i] = (tr2[i] + c) % p;
}
}
PII query(int x){
PII res = {
0, 0};
for(int i = x; i ; i -= i & -i){
if(res.fi < tr[i]) res.fi = tr[i], res.se = tr2[i];
else if(res.fi == tr[i]) res.se = (res.se + tr2[i]) % p;
}
return res;
}
};
AC代码:http://oj.daimayuan.top/submission/326785
#922. 子串(数据加强版)
题意:给定一个长度为 n ( 1 ≤ n ≤ 2500 ) n(1\leq n\leq 2500) n(1≤n≤2500) 的 01 01 01 串,Ask how many divisions there are,Makes each of the divided substrings 1 1 1 The sequence of numbers is palindromic,答案对 998244353 998244353 998244353 取模.
题解:(插板法)代码源每日一题 Div1 子串(数据加强版)
思路:The data of the original title can use the interval DP 来做.Optimize with double pointers,The left pointer enumerates the division points from left to right,Slide the right pointer to the corresponding point,然后统计.
The solution is to use combination counting.
AC代码:borders are bad,没有AC.
边栏推荐
- 51单片机驱动HMI串口屏,串口屏的下载方式
- 剑指offer专项突击版第25天
- SQLserver加个判断
- What makes training multi-modal classification networks hard?
- Shell编程--awk
- 【二叉树-中等】508. 出现次数最多的子树元素和
- C# winform 单选框
- Redis - Basic operations and usage scenarios of String|Hash|List|Set|Zset data types
- 别再用 offset 和 limit 分页了,性能太差!
- 2022.8.9 Exam Unique Bid Auction--800 Question Solutions
猜你喜欢
随机推荐
【二叉树-中等】1104. 二叉树寻路
Under pressure, there must be cowards
UXDB现在支持函数索引吗?
storage of data in memory
[Kali Security Penetration Testing Practice Course] Chapter 9 Wireless Network Penetration
C# 正则表达式分组查询
【二叉树-简单】112. 路径总和
实例048:数字比大小
手把手教你搭建ELK-新手必看-第一章:什么是ELK?
浅写一个下拉刷新组件
牛客刷题——剑指offer(第四期)
2022.8.9考试独特的投标拍卖--800题解
What makes training multi-modal classification networks hard?
QT中,QTableWidget 使用示例详细说明
RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
GDB command basic parameters
2022.8.9 Exam Travel Summary
翻译工具-翻译工具下载批量自动一键翻译免费
How Microbes Affect Physical Health
跨站请求伪造(CSRF)攻击是什么?如何防御?