Meaning of the questions:
There are n line segments, each segment covering points [L I , R & lt I ], if the points are more than k line segments covering, then the point of dead pixels,
Q. Which at least a few segments removed, can make no dead pixels?
Ideas:
Point sweep from left to right, if the point of dead pixels, then remove some of the points covered in this segment, from r i s largest delete start, no need to consider L i is because you have left to ensure that no dead pixels, then delete out of the line of course R & lt I better.
Multiset line with current maintenance coverage at this point is which a few.
I know today, sort when the externally defined function cmp structure may be covered in the overloaded operators '<'.
It is not really a big brother less stl, when the test sample RE, the two cross-hair is also RE, long tone.
Code:
#include <stdio.h> #include <string.h> #include <cmath> #include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; typedef long long int ll; const double pi = acos(-1); const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; struct node { int l,r,id; friend bool operator <(node x,node y){ return x.r < y.r; } }a[maxn]; bool cmp(node x,node y) { return x.l < y.l; } int vis[maxn]; multiset<node>st; int main() { multiset<node>::iterator it; int n,k,ans,mx; while(scanf("%d%d",&n,&k) != EOF){ ans = 0; mx = 0; st.clear(); memset(vis,0,sizeof(vis)); for(int i = 1;i <= n;i++){ scanf("%d%d",&a[i].l,&a[i].r); mx = max(mx,a[i].r); a[i].id = i; } sort(a + 1,a + n + 1,cmp); int cnt = 1,now = 0; for(int i = 1;i <= mx;i++){ it = st.begin(); while(it != st.end() && (*it).r < i){ st.erase(it); it = st.begin(); now--; } while(cnt <= n && a[cnt].l <= i){ st.insert(a[cnt]); cnt++; now++; } it = st.end(); while(now > k){ it--; vis[(*it).id] = 1; st.erase(it); it = st.end(); now--; ans++; } } printf("%d\n",ans); for(int i = 1;i <= n;i++){ if(vis[i]) printf("%d ",i); } puts(""); } return 0; }