Address: poj 2352
Today's weekly competition was abused .. Tat... the line segment tree is too scum .. You have to make up for it (though it was learned from yesterday .. Cannot be supplemented ...)
This question is still very simple .. Maintenance Information is the number of times each abscissa appears.
The Code is as follows:
# Include <iostream> # include <cstdio> # include <string> # include <cstring> # include <stdlib. h> # include <math. h> # include <ctype. h> # include <queue> # include <map> # include <set> # include <algorithm> using namespace STD; # define lson L, mid, RT <1 # define rson Mid + 1, R, RT <1 | 1 struct node {int X, Y;} star [40000]; int CMP (node X, node y) {If (X. y = y. y) {return X. x <Y. x;} return X. Y <Y. y;} int sum [323000], _ Hash [130000]; void pushup (int rt) {sum [RT] = sum [RT <1] + sum [RT <1 | 1];} void Update (int x, int L, int R, int RT) {If (L = r) {sum [RT] ++; return;} int mid = L + r> 1; if (x <= mid) Update (X, lson); else Update (x, rson); pushup (RT);} int query (int ll, int RR, int L, int R, int RT) {If (LL <= L & RR> = r) {return sum [RT];} int mid = L + r> 1; int ans = 0; if (LL <= mid) ans + = query (LL, RR, lson); If (RR> mid) ans + = query (LL, RR, rson ); return ans;} int main () {int n, x, y, I, j, ANS, max1 =-1; scanf ("% d", & N ); memset (sum, 0, sizeof (SUM); for (I = 0; I <n; I ++) {scanf ("% d ", & star [I]. x, & star [I]. y); If (max1 <star [I]. x) max1 = star [I]. x;} Sort (Star, star + N, CMP); memset (_ Hash, 0, sizeof (_ Hash); for (I = 0; I <N; I ++) {ans = query (0, star [I]. x, 0, max1, 1); Update (Star [I]. x, 0, max1, 1); _ Hash [ANS] ++ ;}for (I = 0; I <n; I ++) {printf ("% d \ n", _ Hash [I]);} return 0 ;}