Normal: f[i]=max{f[i-1],f[x-1]+c[x,i]} f[0]=0
c[x,i]表示x玩到i的快乐值
Rare: 加单调队列优化
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define N 500100
#define M 300000
struct node{int x,y,c;} e[M];
int n,T,tot,tree[N];
inline void read(int &x)
{
x=0; char ch; while(ch=getchar(),ch>'9' || ch<'0');
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
}
inline int Max(int x,int y){return x>y?x:y;}
inline bool cmp(node A,node B){ return A.y<B.y; }
inline void insert(int x,int y){
for(;x<=T;x+=x&-x) tree[x]=Max(tree[x],y);
}
inline int Query(int x){
int ret=0;
for(;x;x-=x&-x) ret=Max(ret,tree[x]);
return ret;
}
int main()
{
freopen("net.in","r",stdin);
freopen("net.out","w",stdout);
read(n); read(T);
for(int i=1,m;i<=n;i++)
{
read(m);
for(;m--;) {
++tot;
read(e[tot].x);
read(e[tot].y);
read(e[tot].c);
}
}
sort(e+1,e+1+tot,cmp);
for(int i=1,tmp;i<=tot;i++)
{
tmp=Query(e[i].x-1)+e[i].c;
if(tmp>Query(e[i].y))
insert(e[i].y,tmp);
}
printf("%d\n",Query(T));
return 0;
}