Description 给出 \(n\) 个数 \(a_i\),每一个数有一个取值 \([l_i,r_i]\) ,你来确定每一个数,使得 \(LIS\) 最大 题面 Solution 按照平时做法,设 \(f[i]\) 表示 \(LIS\) 长为 \(i\) 时, \(LIS\) 结尾的最小值 考虑插入一个取值为 \([L,R]\) 可以更新的值 找到小于 \(L\) 的第一个数 \(p\) 和小于 \(R\) 的第一个数 \(q\) 那么 \(f[p+1]\) 可以更新为 \(L\) , \(…
题意 给你长度为$n$的序列,序列中的每个元素$i$有一个区间限制$[l_i,r_i]$,你从中选出一个子序列,并给它们标号$x_i$,要求满足 $,∀i<j,x_i<x_j$,且$, ∀i,x_i∈[l_i,r_i]$. 问满足条件子序列的长度最长为多少? 其中$1\leq n\leq3\times 10^5\ 1\leq l_i\leq r_i\leq 10^9$ 题解 不妨设$f[i][j]$表示已经选到第$i$个,其中最大值为$j$最多能选几个. 显然是开不下的...但是还记得$O(n…
题目:http://codeforces.com/contest/809/problem/D 如果值是固定的,新加入一个值,可以让第一个值大于它的那个长度的值等于它. 如今值是一段区间,就对区间内的dp值都有影响:中间的那些的值变成了上一个的值+1,左边 l 处多了一个点,右边第一个大于等于 r 的点被删掉. 用 splay 维护这些点:点的个数就是最多能达到的长度. 又好好学习了一番 splay .带有标记的原来是要在那个 splay 操作前那样一条链地 pushdown下来呀. 非常奇怪的是…
[CF809D]Hitchhiking in the Baltic States(Splay,动态规划) 题面 CF 洛谷 题解 朴素\(dp\):设\(f[i][j]\)表示当前考虑到第\(i\)个元素,结尾位置是\(j\)的最大选择数. 然而这样就很呆. 换个状态:设\(f[i][j]\)表示当前考虑到第\(i\)个元素,长度为\(j\)时,最后一个数可以选择的最小值. 这个东西看起来就舒服多了. 拿\(Splay\)维护第二维,考虑每次加入一个区间对于答案的影响,假装当前加入区间是\([l…
[CF809D]Hitchhiking in the Baltic States 题意:给你n个区间[li,ri],让你选出从中一个子序列,然后在子序列的每个区间里都选择一个tj,满足$t_1<t_2<...<t_{len}$.最大化这个子序列的长度. $1\le n\le 3\cdot 10^5,1\le l\le r \le 10^9$ 题解:我们用dp[i]表示在当前情况下,选择的最后一个$t\le i$时,最多能选多少个区间.然后我们加入每个区间,同时维护所有的dp值. 当加入区…
CF809D Hitchhiking in the Baltic States CF809D 长度为n的序列{xi},n<=3e5,范围在(li,ri)之间,求LIS最长是多长g(i,l)表示前i个数,LIS长度为l,最后一个数最小是多少(就是那个单调栈)g(i,l)=min(g(i-1,l),xi (if exist j g(j,l-1)<x))关于l是递增的.虽然不知道xi是多少, 但是可以直接用(li,ri)进行计算!最后一定存在一种方法还原xi 刚好可以把一个g(i-1,l-1)+1-…
题目:http://codeforces.com/contest/809/problem/D 看题解,抄标程...发现自己连 splay 都快不会写了... 首先,题目就是要得到一个 LIS: 但与一般不同的是,新加入的不是一个值,而是一个取值范围: 仍是设 f[i] 表示长度为 i 的 LIS 的结尾最靠前是哪个位置,而此时新出现一个区间 l~r: 如果 f[i] < l,那么可以接上一个 l 变成 f[i+1],也就是 f[i+1] = l: 如果 l <= f[i] <= r,也可…
题意: 给你n个区间[li,ri],让你选出从中一个子序列,然后在子序列的每个区间里都选择一个tj,满足t1<t2<...<tlent1<t2<...<tlen.最大化这个子序列的长度. 1≤n≤3⋅105,1≤l≤r≤109 题解: 首先我们很容易想到n^2的递推式 f[i]表示最后一个是i f[i]=max(f[i],max(f[j])+1) (l<=i<=r) 那么这样是可以O(n^2)扫一遍的 然后会发现这个东西不太好优化 我们很自然的会想到用前缀g…
传送门 看到最长上升子序列肯定是DP 设\(f_i\)表示计算到当前,长度为\(i\)的最长上升子序列的最后一项的最小值,显然\(f_i\)是一个单调递增的序列. 转移:对于当前计算的元素\(x\),它的取值范围为\([l,r]\),设当前可以转移的区间为\([j,k]\)(即对于\(\forall p \in [j,k] , f_p \in [l,r)\)且\(f_{j-1} < l , f_{k + 1} \geq r\)),则对于\(\forall p \in [j,k]\)都有\(f_{…
题目大意:有一个M*N的矩阵,在这个矩阵里面有三个王国,编号分别是123,想知道这三个王国连接起来最少需要再修多少路. 分析:首先求出来每个王国到所有能够到达点至少需要修建多少路,然后枚举所有点求出来最少的即可. 代码如下: --------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<…
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noip前的杂题训练,我也很无奈啊 做完了的扔最后,欢迎好题推荐 这么多题肯定是完不成了,能多做一道是一道吧 DP yyb真是强得不要不要的辣:http://www.cnblogs.com/cjyyb/category/1036536.html [ ] [SDOI2010]地精部落 https://www…
World Country Profile: Aggregate functions This tutorial is about aggregate functions such as COUNT, SUM and AVG. An aggregate function takes many values and delivers just one value. For example the function SUM would aggregate the values 2, 4 and 5…
E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem/E Description The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed…
题目链接: C. Three States time limit per test 5 seconds memory limit per test 512 megabytes input standard input output standard output The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an allia…
题目链接: 题目 E. Three States time limit per test:5 seconds memory limit per test:512 megabytes 问题描述 The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all…
E. Three States Problem's Link Mean: 在一个N*M的方格内,有五种字符:'1','2','3','.','#'. 现在要你在'.'的地方修路,使得至少存在一个块'1','2'和'3'是连通的. 问:最少需要修多少个'.'的路. analyse: 想法题,想到了就很简单. 直接暴力枚举每个国家到每个可达的点的最小代价,然后计算总和取最小值. dis[k][x][y]表示第k个国家到达坐标(x,y)的点的最小代价. Time complexity: O(N) vi…
题目链接:http://codeforces.com/contest/591/problem/E 题意:有3个数字表示3个城市,每种城市都是相互连通的,然后不同种的城市不一定联通,'.'表示可以建设道路‘#’表示 不能,问最短建设多少道路能够让3种城市都联通起来 题解:直接bfs一遍所有类型的城市,bfs的同时更新第i类城市到(x,y)点的最短距离,更新第i类城市到第j类城市的距离 具体看一下代码. #include <iostream> #include <cstring> #i…
C. Three States time limit per test 5 seconds memory limit per test 512 megabytes input standard input output standard output The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance an…
Three Statesy 题解: 以3个大陆为起点,都dfs一遍,求出该大陆到其他点的最小距离是多少, 然后枚举每个点作为3个大陆的路径交点. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL…
A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nic…
Variable, or There and Back Again 题目连接: http://codeforces.com/problemset/problem/164/A Description Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used! V…
A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/337/A Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to p…
D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/problem/D Description As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State Uni…
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Noura Boubou is a Syrian volunteer at ACM ACPC (Arab Collegiate Programming Contest) since 2011. She graduated from Tishreen Un…
H. Bots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/H Description Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are…
http://codeforces.com/problemset/problem/1040/B Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over. This time Miroslav laid out…
2018-03-16 http://codeforces.com/problemset/problem/697/C C. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Barney lives in NYC. NYC has infinite number of intersect…
C. Felicity is Coming! time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan…
E. ZS and The Birthday Paradox 题目连接: http://www.codeforces.com/contest/711/problem/E Description ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% c…
题目链接:http://codeforces.com/contest/440/problem/D D. Berland Federalization   Recently, Berland faces federalization requests more and more often. The proponents propose to divide the country into separate states. Moreover, they demand that there is a…