当前位置:网站首页>[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.
边栏推荐
猜你喜欢
Fusion Compute网络虚拟化
Deep Learning (5) CNN Convolutional Neural Network
Process management and task management
In automated testing, test data is separated from scripts and parameterized methods
月薪35K,靠八股文就能做到的事,你居然不知道
2022杭电多校联赛第七场 题解
【Kali安全渗透测试实践教程】第8章 Web渗透
实例047:函数交换变量
【Kali安全渗透测试实践教程】第9章 无线网络渗透
ArcGIS Advanced (1) - Install ArcGIS Enterprise and create an sde library
随机推荐
Algorithm and voice dialogue direction interview question bank
C# winform 单选框
Process management and task management
Will signal with different start time alignment
在蓝图中给组件动态加子Actor组件
web crawler error
小菜鸟河北联通上岗培训随笔
Database management tool: dynamic read-write separation
LeetCode 每日一题——1413. 逐步求和得到正数的最小值
ImportError: Unable to import required dependencies: numpy
2022杭电多校联赛第七场 题解
2022.8.8 Exam area link (district) questions
《GB39707-2020》PDF download
2022.8.8 Exam written in memory (memory)
谷歌翻译器-谷歌翻译器软件批量自动翻译
The 25th day of the special assault version of the sword offer
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
2022年立下的flag完成情况
数据挖掘和数据仓库之间的区别
mysql -sql编程