题意:给一个序列以及\(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. 获取url参数的方法(web)

    //获取url参数的方法(web) function GetQueryString(name) {     var reg = new RegExp("(^|&)" + n ...

  2. CloudSim源代码学习——任务单元(Cloudlet)

    /* * Title: CloudSim Toolkit * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Sim ...

  3. NoHttp封装--05 文件下载

    xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:la ...

  4. Django基础篇--Models

    在Django中创建与数据库的链接并调用数据库的数据是很关键的步骤,那么怎么实现这个过程呢? 下面这篇文章简单梳理了一下创建Model层的过程和应用 模型-Models 首先需要理解什么是模型? 模型 ...

  5. Python鸢尾花分类实现

    #coding:utf-8 from sklearn.datasets import load_irisfrom sklearn.model_selection import train_test_s ...

  6. c#事务处理(sqlTransaction)

    事务: /// <summary> /// 删除考勤 /// </summary> /// <param name="dto">Id</p ...

  7. npm与yarn常用命令对比

    最近在用yarn,但是命令老是记不住,在此记录,方便日后翻看 图片截取自:http://yuanhehe.cn/2017/06/11/npm-%E4%B8%8E-Yarn-%E5%B8%B8%E7%9 ...

  8. Column Index out of range, 2 > 1 列索引的范围,2 > 1。

    Column Index out of range, 2 > 1  列索引的范围,2 > 1.这个问题是进行数据库查询的时候出现的. 因为查询sql语句时 只查询了 name 然后whil ...

  9. MailKit帮助类

    public class EmailHelp { /// <summary> /// Smtp服务器地址 /// </summary> private static reado ...

  10. 软件发布时的 GA、RC、Beta

    今天在使用 ovirt 的时候,遇到了其 Pre-release 版本并看到如下版本号:ovirt-node-ng-image-update-4.2.7-0.1.rc1.el7.noarch.rpm ...