题意:给一个序列以及\(n\)个查询,每一个查询是问(假装)把第\(a_i\)个数改为\(b_i\)之后原序列的最长上升子序列的长度。

思路:线段树优化\(dp\)。

肯定离线做啊。

首先我们考虑\(dp\)的状态是\(dp_L(i)\)表示以第\(i\)位为结束的最长上升子序列的长度和方案数\(mod\ 998244353\)。

之所以方案数要模某个数是因为这个方案数太大太大了,肯定爆\(long\ long\)。

就因为这个我\(wa\)了一次\(test\ case\ 13\)。

开心的不得了呢

\(dp_R(i)\)的定义类似,只是以\(i\)为开始而已。

考虑转移,以\(dp_L\)为例。

\(dp_L(i)=dp_L(j)+1\)当且仅当\(j<i and a_j < a_i\)。

那么这肯定可以用线段树来维护啊。

只需要用一个单点修改、区间查询的zkw就好了。

那么我们考虑把\(i\)换掉之后会发生什么。

首先新的LIS可以分成两部分考虑:

  • 必须包含新的数,那么就是我们可以考虑把\(i\)按照原来的\(dp\)方式转移,只不过需要添加查询数的\(dp\)值。
  • 不能包含新的数,那么有点难考虑。
    但是我们知道一个性质:如果我们所有的原来的LIS都经过这原来的数,
    那么现在不经过原来数的LIS最大也不会超过原来的-1,而且是肯定能够达到的。
    我们只需要统计经过原来这个数的LIS个数。
    也就是\(dp_L(i)*dp_R(i)\)。

然后取必须包含这一位和必须不包含的\(max\)就是答案了。

【Codeforces 650 D】Zip-line的更多相关文章

  1. 【Codeforces Rockethon 2014】Solutions

    转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engi ...

  2. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【17.76%】【codeforces round 382C】Tennis Championship

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【21.21%】【codeforces round 382D】Taxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【CodeForces 353 A】Domino

    [链接] 我是链接,点我呀:) [题意] [题解] 分类讨论一波 设第一个数组的奇数个数为cnt1 第二个数组的奇数个数为cnt2 显然只有在(cnt1+cnt2)%2==0的情况下. 才可能第一个数 ...

  9. 【Codeforces Round 418】An impassioned circulation of affection DP

                                                            C. An impassioned circulation of affection   ...

随机推荐

  1. c++类构造函数详解

    //一. 构造函数是干什么的 /*   类对象被创建时,编译系统对象分配内存空间,并自动调用该构造函数->由构造函数完成成员的初始化工作      eg: Counter c1;      编译 ...

  2. cordova启动页面和图标的设置

    一.config.xml配置 在cordova5.0版本以后,需要安装cordova-plugin-splashscreen插件以后才能修改和设置App的启动页面. 安装splashscreen插件: ...

  3. Spring Boot Oauth2缓存UserDetails到Ehcache

    在Spring中有一个类CachingUserDetailsService实现了UserDetailsService接口,该类使用静态代理模式为UserDetailsService提供缓存功能.该类源 ...

  4. spring 开发 Tars

    和不使用 Spring 的 tars HelloWord 项目相比,客户端完全一样,服务端两个地方不一样 创建不使用 Spring 的 tars HelloWord 步骤: https://www.c ...

  5. XSS(跨站脚本攻击)漏洞解决方案

    首先,简单介绍一下XSS定义: 一 . XSS介绍 XSS是跨站脚本攻击(Cross Site Scripting)的缩写.为了和层叠样式表CSS(Cascading Style Sheets)加以区 ...

  6. 在td中的输入英文为什么不自动换行???

    在表格中如果输入纯汉字,表格中的内容会根据表格大小进行换行,若果一个老外不会写汉字,写了一堆英文,表格的宽度会拉的很长,超过规定宽度 解决方法是在table中加上style="table-l ...

  7. 遇到npm报错read ECONNRESET怎么办

    遇到npm 像弱智一样报错怎么办 read ECONNRESET This is most likely not a problem with npm itselft 'proxy' config i ...

  8. Linux命令大全总结

    目录方面的命令:ls,dir,cd,clear,mkdir ls 显示指定目录的文件和目录 ls -a 列出目录下的所有文件,包括以 . 开头的隐藏文件 ls -l 显示指定目录的详细列表 ls -R ...

  9. Java中BufferedReader到底是一个什么类?

    1.java.io.BufferedReader 和 java.io.BufferedWriter 类各拥有8192字符的缓冲区.当BufferedReader在读取文本文件时,会先尽量从文件中读入字 ...

  10. vue 去除前后空格trim

    一.使用trim修饰符 <input v-model.trim = "massage" > 二.使用filter过去属性 html: <ul id="l ...