传送门
文章目录
- 题意:
- 思路:
题意:
思路:
比较套路的一个题,我们维护一个dp[i]dp[i]dp[i]表示到了第iii行能保留的区间最多是多少。
转移比较明显:dp[i]=max(dp[j])dp[i]=max(dp[j])dp[i]=max(dp[j])
其中jjj能转移到iii当且仅当他们之间有交集。
考虑到有1e91e91e9的范围,用线段树来判断的话可以动态开点也可离散化,这里写了个动态开点给卡过去了。
用线段树维护一下区间最大值的ididid,让后维护一个dpdpdp即可。
// Problem: D. Ezzat and Grid
// Contest: Codeforces - Codeforces Round #737 (Div. 2)
// URL: https://codeforces.com/contest/1557/problem/D
// Memory Limit: 256 MB
// Time Limit: 2500 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=300010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m,root,tot;
int dis[N],pre[N];
bool st[N];
struct Node {int l,r;int id,lid;
}tr[10900000];
vector<int>v[N];
vector<PII>q[N];void change(int &u,int l,int r,int ql,int qr,int id) {if(!u) u=++tot;if(dis[id]>dis[tr[u].id]) tr[u].id=id;if(l>=ql&&r<=qr) {if(dis[id]>dis[tr[u].lid]) tr[u].lid=id;return;}int mid=(l+r)>>1;if(ql<=mid) change(tr[u].l,l,mid,ql,qr,id);if(qr>mid) change(tr[u].r,mid+1,r,ql,qr,id);
}void query(int &u,int l,int r,int ql,int qr,int &id) {if(!u) return;if(dis[tr[u].lid]>dis[id]) id=tr[u].lid;if(l>=ql&&r<=qr) {if(dis[tr[u].id]>dis[id]) id=tr[u].id;return;}int mid=(l+r)>>1;if(ql<=mid) query(tr[u].l,l,mid,ql,qr,id);if(qr>mid) query(tr[u].r,mid+1,r,ql,qr,id);
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0); scanf("%d%d",&n,&m);for(int i=1;i<=m;i++) {int id,l,r; scanf("%d%d%d",&id,&l,&r);q[id].pb({l,r});}int ans=0; dis[0]=0;for(int i=1;i<=n;i++) {for(auto x:q[i]) {int l=x.X,r=x.Y;int mx=0,id=0;query(root,1,1e9,l,r,id);if(dis[i]<dis[id]+1) dis[i]=dis[id]+1,pre[i]=id;}for(int j=0;j<q[i].size();j++) {int l=q[i][j].X,r=q[i][j].Y;change(root,1,1e9,l,r,i);}}int id=0;for(int i=1;i<=n;i++) if(ans<dis[i]) ans=dis[i],id=i;cout<<n-ans<<endl;st[id]=1; int cnt=0; while(pre[id]) {id=pre[id],st[id]=1;}for(int i=1;i<=n;i++) if(!st[i]) printf("%d ",i); puts("");return 0;
}
/**/