Since the subject has the sequence according to the row y
So we scanned according to the order given each star
Because it has not been scanned into the top, so we have to count all scanned x is less than the stars of x
That we renumber all the stars of the abscissa
Set C [x] represents the number renumbering have few stars x
So every time we just count c [1] to c [x] and to
As it relates to each scan the stars have to modify c
So take advantage of Fenwick tree
The Code
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define int long long using namespace std; int n,book[15000050],c[1500050],cnt,ans[1500050]; struct node{ int x,y; }p[1500050],p1[1500050]; int lowbit(int x) { return x&(-x); } bool cmp(node a,node b) { return a.x<b.x; } void updata(int i,int x) { int temp=i; while(temp<=n) { c[temp]+=x; temp+=lowbit(temp); } } int query(int i) { int res=0; while(i>=1) { res+=c[i]; i-=lowbit(i); } return res; } signed main() { scanf("%lld",&n); for(int i=1;i<=n;i++) scanf("%lld%lld",&p[i].x,&p[i].y),p1[i].x=p[i].x,p1[i].y=p[i].y; sort(p1+1,p1+n+1,cmp); for(int i=1;i<=n;i++) if(!book[p1[i].x])book[p1[i].x]=++cnt;//排序重编号 for(int i=1;i<=n;i++) { UPDATA (Book [P [I] .x], . 1 ); // The statistics on this star ++ ANS [Query (Book [P [I] .x])]; // count prefix and // for (int. 1 = J; J <= n-; J ++) the printf ( "% LLD", C [J]); // the putchar ( '\ n-'); // for (int. 1 = J; J <= n-; J ++) the printf ( "% LLD", ANS [J]); // the putchar ( '\ n-'); } for ( int I = . 1 ; I <= n-; I ++) the printf ( " % LLD \ n- " , ANS [I]); return 0 ; }