Another Longest Increasing Subsequence Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19929 Description Given a sequence of N pairs of integers, find the length of the longest incre…
题目链接  LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --…
cdq分治,dp(i)表示以i为结尾的最长LIS,那么dp的递推是依赖于左边的. 因此在分治的时候需要利用左边的子问题来递推右边. (345ms? 区间树TLE /********************************************************* * ------------------ * * author AbyssFish * **********************************************************/ #inclu…
SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给定 N个数对 \((x_i,y_i)\),求最长上升子序列的长度.上升序列定义为满足\((x_i,y_i)\)对i<j 有 \(x_i<x_j\) 且 \(y_i<y_j\) 题解: 一个三维最长链问题 第一维是存位置,第二维存x,第三维存y 注意查询是查询到p[i].z-1然后更新 细节方…
分析 这回试了一下三级标题,不知道效果怎么样? 回到正题,二维最长上升子序列......嗯,我会树套树. 考虑\(CDQ\)分治,算法流程: 先递归进入左子区间. 将左,右子区间按\(x\)排序. 归并处理左右子区间,在过程中使用树状数组加速\(DP\). 还原右区间,清空树状数组. 递归进入右子区间. 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring>…
Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it. An increasing sequence A1..An is a sequence such that for every i < j, Ai < Aj. A subsequence of a sequence is a sequence that appears in the same…
在solve(L,R)中,需要先分治solve两个子区间,再计算左边区间修改对右边区间询问的贡献. 注意,计算额外的贡献时,两子区间各自内部的顺序变得不再重要(不管怎么样左边区间的都发生在右边之前),于是就少了一维 https://www.lydsy.com/JudgeOnline/problem.php?id=3262 https://www.luogu.org/problemnew/show/P3810 此题每个操作既是修改又是查询 对于此题,先按一维排序,在solve(L,R)中先solv…
题目背景 这是一道模板题 可以使用bitset,CDQ分治,K-DTree等方式解决. 题目描述 有 nn 个元素,第 ii 个元素有 a_iai​.b_ibi​.c_ici​ 三个属性,设 f(i)f(i) 表示满足 a_j \leq a_iaj​≤ai​ 且 b_j \leq b_ibj​≤bi​ 且 c_j \leq c_icj​≤ci​ 的 jj 的数量. 对于 d \in [0, n)d∈[0,n),求 f(i) = df(i)=d 的数量 输入格式 第一行两个整数 nn.kk,分别表…
题目链接 思路 对一维排序后,使用$cdq$分治,以类似归并排序的方法处理的二维,对于满足$a[i].b \leq a[j].b$的点对,用树状数组维护$a[i].c$的数量.当遇到$a[i].b>a[j].b$时可以更新$j$的答案,因为前半部分中剩余的点的第二维必然大于$j$点的第二维(记住我们是对第二维进行归并排序所以第二维是有序的,因此有这样的判断).每次要记得初始化树状数组. 代码 #include <bits/stdc++.h> #define DBG(x) cerr <…
十分巧妙. Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) freopen(s".in","r",stdin) #define maxn 200000 #define N 3000000 #define ll long long using namespace std; int k,n; int C[N],ans[ma…