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