思路:
总纲是贪心,按终点排序,然后优先往右边排能量塔。具体实现的时候需要单点更新,区间查询,所以用树状数组+set维护一下,就OK了。
代码:(不知道为啥有一个样例RE了)
#include<bits/stdc++.h> using namespace std;
const int MAX = 2e5 + 10;
int c[200050];
int lowbit(int x) {return x & -x;}
void add(int x, int val) {while(x < MAX) {c[x] += val;x += lowbit(x);}
}
int sum(int x) {int res = 0;while(x > 0 ) {res += c[x];x -= lowbit(x);}return res;
}
int query(int l, int r) {return sum(r) - sum(l-1);
}
int n,b;
struct Node {int s,e;int t;
};
Node nn[MAX+10];
bool cmp(Node a, Node b) {return a.e < b.e;
}
set<int> ss;
int main( )
{cin>>n>>b;for(int i = 0; i<b; i++) {cin>>nn[i].s>>nn[i].e>>nn[i].t;}for(int i = 1; i<=n; i++) ss.insert(i);sort(nn, nn+b, cmp);for(int i = 0; i<b; i++) {int now = query(nn[i].s, nn[i].e);if(now >= nn[i].t) continue;while(now < nn[i].t) {auto it = ss.lower_bound(nn[i].e);if(*it >= nn[i].e) --it;add(*it, 1);ss.erase(it);now++;}}cout << sum(MAX-1);return 0;
}