当前位置:网站首页>[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.
边栏推荐
猜你喜欢
随机推荐
what is a microcontroller or mcu
2022.8.9 Exam Unique Bid Auction--800 Question Solutions
翻译工具-翻译工具下载批量自动一键翻译免费
flask增删改查
基于误差状态的卡尔曼滤波ESKF
liunx PS1 设置
QT中,QTableWidget 使用示例详细说明
UXDB现在支持函数索引吗?
OpenCV图像处理学习四,像素的读写操作和图像反差函数操作
《GB39707-2020》PDF download
storage of data in memory
web crawler error
【二叉树-中等】687. 最长同值路径
FusionCompute产品介绍
Pagoda server PHP+mysql web page URL jump problem
小菜鸟河北联通上岗培训随笔
Shell编程--awk
2022年8月1日-8月7日(本周10小时,合计1422小时,剩余8578小时)
谷歌翻译器-谷歌翻译器软件批量自动翻译
2022.8.8 exam sweeps the horse (sweeper) antithesis