Tree-like array POJ2352 stars

Source: Internet
Author: User

http://poj.org/problem?id=2352

The problem of the test instructions for the living scholar should be more difficult to understand, but if you understand his meaning, you will find that this is a naked tree array, ah, bullying I do not understand is it, then read the question for a long time, OK, let's say what he means.

Because the title already shows that y coordinates are ascending order, it is OK to consider the coordinates of X directly. Each time there is an x input, the value of sum (x+1) is calculated (note, in the tree array, but starting from 1, and the input of the topic is 0), and the Result[sum (x+1)]++; update it again.

Still have to pay attention to one point, use C + + commit timeout, or use C bar!!!!!!!!!!!!!!!!

1#include <stdio.h>2#include <string.h>3#include <algorithm>4#include <iostream>5 Const intn=32005;6 using namespacestd;7 intc[n+1];8 intN;9 intLowbit (inti) {Ten returni& (-i); One } A voidAddintIintx) - { -      while(i<=N) { thec[i]+=x; -i+=lowbit (i); -     } - } + intSuminti) - { +     ints=0; A      while(i>0){ ats+=C[i]; -i-=lowbit (i); -     } -     returns; - } - intMain () { in intb; - intResult[n]; toscanf"%d",&n); +        //memset (result,0,sizeof (Result)); -         //memset (c,0,sizeof (c)); the      for(intI=0; i<n;i++){ *scanf"%d%d",&a,&b); $         intTemp=sum (A +1);Panax Notoginsengresult[temp]++; -Add (A +1,1); the     } +      for(intI=0; i<n;i++){ Acout<<result[i]<<Endl; the     } +}
View Code

Tree-like array POJ2352 stars

Related Article

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.