Topic Link http://acm.hdu.edu.cn/showproblem.php?pid=5517
-------------------------------------------------------------------------------------------------------
Pre-knowledge and the difficulty of thinking is not very high but the implementation for my weak slag is still too complex (a lot of processing compared around)
After we have a little analysis (Xiangyun), we can find that the essentially different triples C have no more than M
For the two tuple a B is the same, only the largest one is reserved and the same A is merged
After processing, the B will not be more than M C
At this point, sort by an element and then count the other two elements with a two-dimensional tree array.
-------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>using namespacestd;Const intN = 1e5 +Ten, Lim =1001;intt, N, M, Len, Lenm;structsa{intX,y,c;} A[n],ua[n];structsc{intX,y,z,c;} C[n];BOOLF[lim][lim];BOOLCMP1 (ConstSA &aa,ConstSA &b) { returnAa.y < BB.Y | | (Aa.y = = Bb.y && aa.x >bb.x);}BOOLCMP2 (ConstSC &aa,ConstSC &BB) { returnaa.x > Bb.x | | (aa.x = = bb.x && Aa.y <bb.y)|| (aa.x = = bb.x && aa.y = = Bb.y && aa.z <bb.z);}intMain () {scanf ("%d", &t); for(intCA =1; CA <= T; ++CA) {scanf ("%d%d", &n, &m); for(inti =1; I <= N; ++i) scanf ("%d%d", &a[i].x, &a[i].y); Sort (a+1, A +1+N, CMP1); Len= Lenm =0; memset (UA,0,sizeofUA); for(inti =1; I <=N;) { ++Len; ua[len].x=a[i].x; Ua[len].y=a[i].y; intj =i; while(A[j +1].x = =a[i].x)++J; UA[LEN].C= J-i +1; while(A[j]. y = =a[i].y)++J; I=J; } intTx,ty,tz; for(inti =1; I <= m; ++i) {scanf ("%d%d%d", &tx, &ty, &TZ); intL =1, R =Len, Mid; while(L <R) {Mid= (L + R) >>1; if(Ua[mid].y >=TZ) R=mid; ElseL= Mid +1; } if(Ua[r].y = =TZ) { ++Lenm; c[lenm].x=ua[r].x; C[lenm].y= Lim-TX; C[lenm].z= Lim-Ty; C[LENM].C=ua[r].c; }} N=Lenm; Sort (c+1, C +1+N,CMP2); Memset (F,0,sizeoff); Long LongAns =0; for(inti =1; I <= N; ++i) {if(c[i].x = = C[i +1].x && C[i].y = = C[i +1].y &&c[i].z= = C[i +1].z) {c[i+1].C + =c[i].c; Continue; } BOOLTMP =0; for(intp = c[i].y; P; P-= p &-p) for(intQ = c[i].z; Q Q-= Q &-q) TMP|=F[p][q]; if(!tmp) ans+=c[i].c; for(intp = c[i].y; P < Lim; p + = P &-p) for(intQ = c[i].z; Q < Lim; Q + Q &-q) f[p][q]=1; } printf ("Case #%d:%lld\n", CA, ans); } return 0;}
Hdu 5517 Triple