题目链接:hdu 5489 Removed Interval
解题思路
正序一遍LIS,逆序一遍LIS。在正序的时候维护一棵线段树,逆序做的时候可以查询当前位置向前间隔L之后,并且终止val小于当前位置的LIS。
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100005;
#define lson(x) ((x)<<1)
#define rson(x) (((x)<<1)|1)
struct SegTree {
int lc[maxn<<2], rc[maxn<<2], s[maxn<<2];
void pushup(int u) { s[u] = max(s[lson(u)], s[rson(u)]); }
void modify(int u, int x, int v) {
if (lc[u] == rc[u]) {
s[u] = v;
return;
}
int mid = (lc[u] + rc[u]) >> 1;