Tree-like array + discretization of the topic, has been thinking about why the results are not the same, later found that the flowers are open will not be thanked.
1 /*4325*/2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <algorithm>7 using namespacestd;8 9 #defineMAXN 100005Ten Onetypedefstruct { A ints, t; - } node_t; - the node_t NODES[MAXN]; - intQI[MAXN]; - intbuf[maxn*4]; - intSUM[MAXN]; + -InlineintLowbit (intx) { + return-x&x; A } at - voidUpdateintIintVintN) { - while(I <=N) { -Sum[i] + =v; -i + =lowbit (i); - } in } - to intQueryinti) { + intRET =0; - the while(i) { *RET + =Sum[i]; $I-=lowbit (i);Panax Notoginseng } - the returnret; + } A the intMain () { + intt, N, M, L; - intI, J, K, TMP; $ intA, B, C; $ - #ifndef Online_judge -Freopen ("data.in","R", stdin); the #endif - Wuyiscanf"%d", &t); the for(inttt=1; tt<=t; ++TT) { -scanf"%d%d", &n, &m); WuL =0; - for(i=0; i<n; ++i) { Aboutscanf"%d%d", &nodes[i].s, &nodes[i].t); $buf[l++] =Nodes[i].s; -buf[l++] =nodes[i].t; - } - for(i=0; i<m; ++i) { Ascanf"%d", &qi[i]); +buf[l++] =Qi[i]; the } - $ //discretization thebuf[l++] =0; theSort (buf, buf+l); thec = Unique (buf, buf+l)-buf; the -memset (SUM,0,sizeof(sum)); in for(i=0; i<n; ++i) { theA = Lower_bound (buf, Buf+c, NODES[I].S)-buf +1; theb = Lower_bound (buf, Buf+c, nodes[i].t)-buf +1; AboutUpdate (A,1, c); theUpdate (b +1, -1, c); the } the +printf"Case #%d:\n", TT); - for(i=0; i<m; ++i) { thej = Lower_bound (buf, Buf+c, Qi[i])-BUF +1;BayiK =query (j); theprintf"%d\n", k); the } - } - the return 0; the}
"Hdoj" 4325 Flowers