这题并不会做。。
这道题的主要问题是如何求一个区间的最大不相交线段覆盖,思路是可以用倍增来加速贪心。就是说我们本来是求一个区间里最多有多少条线段,我们把它转换成二分/倍增线段数,求其最短的区间是多少。
代码:
#include<cstdio>
#include<iostream>
using namespace std;
#include<algorithm>
#include<cstring>
#include<cmath>
const int N=2e5+5;
int f[N<<1][18];
pair<int,int> range[N];
int hash[N<<1];
bool segt[N<<3];
#define lson node<<1,l,l+r>>1
#define rson node<<1|1,(l+r>>1)+1,r
void paint(int node){
segt[node]=1;
}
void pushup(int node){
segt[node]=segt[node<<1]|segt[node<<1|1];
}
void update(int node,int l,int r,int L,int R){
if(L<=l&&r<=R)paint(node);
if(l==r)return;
if(L<=l+r>>1)update(lson,L,R);
if(R>l+r>>1)update(rson,L,R);
pushup(node);
}
bool query(int node,int l,int r,int L,int R){
if(L<=l&&r<=R)return segt[node];