http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1877Description
now know that there are a total of n room, the total number of Clam Wei has m players, the coach made M-sign, each sign written two number l,r (l<=r), the person to be [l,r] to clean the classroom all over. Because Clam is captain and he's lazy, He knew in advance what was written on all m-signatures through some sort of trade, and he was able to control which sign he drew by some sort of magic. A classroom was cleaned once, so clam wanted to know which signs he smoked without cleaning the classroom and would not be noticed by the coach, that the range he had drawn was cleaned by others.
Clam Wei was called by the coach to clean the computer room, training team has a lot of room, there are many players, now they have to draw a lottery to decide who cleans which classroom.Input
The first behavior is an integer T (1<=t<=20), which represents the number of data groups. The first row of each group of data n,m (1<=n,m<=100000), followed by M-line, two numbers per line l,r (1<=l<=r<=n).
Output
Each set of data output a K, indicating how many signed to meet the requirements of the clam, the next line of output K number, these signed number, subscript starting from 1.
Sample Input3 5 1 4 5 5 6 8 9 5 6 3 6 1 1 1 1 2 2 2 2 3 3 3 3 3 1 4 2 6 6Sample Output2 2 5 6 1 2 3 4 5 6 02016 Light College race missed the question!!!
#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>using namespacestd;#defineEPS 1e-6#defineN 110000#defineMet (A, B) (Memset (A,b,sizeof (a)))#defineLson r<<1#defineRson r<<1|1structe{intL, R;} A[n];intV[n];structnode{intL, R, X; intmid () {return(L+R)/2; } intLen () {return(r-l+1); }}tree[n<<2];voidBuildtree (intRintLintR) {Tree[r]. L= L, Tree[r]. R = r, tree[r].x =0; if(l==R)return ; Buildtree (Lson, L, Tree[r].mid ()); Buildtree (Rson, Tree[r].mid ()+1, R);}voidUpdate (intRintLintR) { if(Tree[r]. L==l && Tree[r]. r==R) {tree[r].x++; return ; } if(r<=Tree[r].mid ()) Update (Lson, L, R); Else if(l>Tree[r].mid ()) Update (Rson, L, R); Else{Update (Lson, L, Tree[r].mid ()); Update (Rson, Tree[r].mid ()+1, R); }}voidUp (intRintLintR) { if(l==R)return ; tree[lson].x+=tree[r].x; tree[rson].x+=tree[r].x; Up (Lson, L, Tree[r].mid ()); Up (Rson, Tree[r].mid ()+1, R); tree[r].x=min (tree[lson].x, tree[rson].x);}intQuery (intRintLintR) { if(Tree[r]. L==l && Tree[r]. r==R)returntree[r].x; if(r<=Tree[r].mid ())returnQuery (Lson, L, R); Else if(l>Tree[r].mid ())returnQuery (Rson, L, R); Else returnMin (Query (Lson, L, Tree[r].mid ()), query (Rson, Tree[r].mid () +1, R));}intMain () {intT; scanf ("%d", &T); while(t--) { intN, M, I, k=0, ans; scanf ("%d%d", &n, &m); Met (A,0); Met (V,0); Buildtree (1,1, N); for(i=1; i<=m; i++) {scanf ("%d%d", &a[i]. L, &A[i]. R); Update (1, A[i]. L, A[i]. R); } Up (1,1, N); for(i=1; i<=m; i++) {ans= Query (1, A[i]. L, A[i]. R); if(ans>=2) V[k++] =i; } printf ("%d\n", K); for(i=0; i<k; i++) printf ("%d%c", V[i], i==k-1?'\ n':' '); } return 0;}
Segment tree range covered Clam cleaning classroom (Zzuli 1877)