"Hdoj" 4325 Flowers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.