Daily questions day7 punch
Analysis
Fenwick tree
As the title of the data to be sorted in the y-axis, we only need to build Fenwick tree x-axis, which means that we only need a total of before i count the number of stars in the x-coordinate of less than or equal to the star Xi, this value is i star rating
And because the tree can not handle an array element at index 0 (circulation will die), so take each x-coordinate +1
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define maxn 15000+10 6 #define maxm 32000+10+1 7 using namespace std; 8 inline int read() 9 { 10 int x=0; 11 bool f=1; 12 char c=getchar(); 13 for(; !isdigit(c); c=getchar()) if(c=='-') f=0; 14 for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+c-'0'; 15 if(f) return x; 16 return 0-x; 17 } 18 inline void write(int x) 19 { 20 if(x<0){putchar('-');x=-x;} 21 if(x>9)write(x/10); 22 putchar(x%10+'0'); 23 } 24 int n; 25 int tree[maxm],ans[maxn]; 26 inline int lowbit(int num) 27 { 28 return num&(-num); 29 } 30 inline void build(int s,int num) 31 { 32 for(int i=s;i<=maxm;i+=lowbit(i)) tree[i]+=num; 33 } 34 inline int ask(int s) 35 { 36 int ans=0; 37 for(int i=s;i>=1;i-=lowbit(i)) ans+=tree[i]; 38 return ans; 39 } 40 int main() 41 { 42 n=read(); 43 for(int i=1;i<=n;i++) 44 { 45 int x,y; 46 x=read();y=read(); 47 x++; 48 int res=ask(x); 49 ans[res]++; 50 build(x,1); 51 } 52 for(int i=0;i<=n-1;i++) 53 { 54 write(ans[i]); 55 printf("\n"); 56 } 57 return 0; 58 }
Please Gangster treatise(Anyway, I do not know what that means treatise)