Title Link: http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877
#include "algorithm" #include "iostream" #include "CString" #include "Cstdio" #include "string" #include "stack" #include " Cmath "#include" queue "#include" set "#include" map "#define Lson l, M, RT << 1#define Rson m + 1, R, RT << 1 | 1typedef long ll;using namespace std;const int inf=0x3f3f3f3f;const int maxn=1e5+5;int t,n,m;struct node{int l,r; }qujian[maxn];bool ok[maxn];int tree[maxn<<2];int col[maxn<<2];void pushUp (int rt) {Tree[rt] = min (tree[rt <<1], tree[rt<<1|1]);} void Push_down (int rt) {if (Col[rt]) {tree[rt<<1]+=col[rt]; tree[rt<<1|1]+=col[rt]; col[rt<<1]+=col[rt]; col[rt<<1|1]+=col[rt]; col[rt]=0; }}void Build (int l,int R,int RT) {col[rt]=0; if (l==r) {tree[rt]=0; Return } int m = (l+r) >>1; Build (Lson); Build (Rson); Pushup (RT);} void update (int l,int r,int l,int r,int RT) {if (l<=l&&r>=r) {Col[rt]++; tree[rt]++; return; } push_down (RT); int m = (l+r) >>1; if (l<=m) update (L,r,lson); if (r>m) update (L,r,rson); Pushup (RT);} int query (int l,int r,int l,int r,int RT) {if (l<=l && r<=r) {return TREE[RT]; } push_down (RT); int m = (l+r) >>1; int ret = INF; if (l<=m) ret = min (ret, query (L,r,lson)); if (r>m) ret=min (ret, query (L,r,rson)); return ret;} int main () {//freopen ("In.txt", "R", stdin); scanf ("%d", &t); while (t--) {scanf ("%d%d", &n,&m); Build (1,n,1); memset (ok,0,sizeof OK); int l,r; for (int i=0;i<m;++i) {scanf ("%d%d", &l,&r); Qujian[i].l=l; Qujian[i].r=r; Update (l,r,1,n,1); } int ans=0; for (int i=0;i<m;++i) {if (query (qujian[i].l,qujian[i].r,1,n,1) >1) {O K[i]=1; ans++; }} printf ("%d\n", ans); BOOL First=1; for (int i=0;i<m;++i) {if (Ok[i]) {if (first) { printf ("%d", i+1); First=false; } else {printf ("%d", i+1); }}} if (ans) printf ("\ n"); } return 0;}
Zzulioj 1877 Clam Wei Cleaning Classroom (line tree)