fork(3) download
  1. #include <bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. #define ft first
  5. #define sd second
  6. #define MAXN 400000
  7.  
  8. int ANS[MAXN],BIT[MAXN] ;
  9.  
  10. void update(int idx,int val=1){
  11.  
  12. while(idx<MAXN){
  13. BIT[idx] += val ;
  14. idx += (idx&-idx) ;
  15. }
  16. }
  17.  
  18. int query(int idx){
  19.  
  20. int s = 0;
  21. while(idx){
  22. s += BIT[idx] ;
  23. idx -= (idx&-idx) ;
  24. }
  25. return s ;
  26. }
  27. int main(){
  28.  
  29. int N ;
  30. scanf("%d",&N) ;
  31. vector<pair<pair<int,int>,int> > A(N+1) ;
  32. for(int i=1;i<=N;i++){
  33. scanf("%d%d",&A[i].ft.ft,&A[i].ft.sd) ;
  34. A[i].sd = i ;
  35. }
  36. sort(A.begin()+1,A.end()) ;
  37.  
  38. int i = 1 ;
  39. while(i<=N){
  40.  
  41. pair<pair<int,int>,int > X ;
  42. int idx ;
  43. X = A[i] ;
  44. idx = i ;
  45. while(i<=N && X.ft.ft == A[i].ft.ft && X.ft.sd == A[i].ft.sd){
  46. ANS[A[i].sd] = query(X.ft.sd) ;
  47. i ++ ;
  48. }
  49. i = idx ;
  50. while(i<=N && X.ft.ft == A[i].ft.ft && X.ft.sd == A[i].ft.sd){
  51. update(X.ft.sd) ;
  52. i ++ ;
  53. }
  54. }
  55. for(int i=1;i<=N;i++)
  56. printf("%d\n",ANS[i]) ;
  57. return 0 ;
  58. }
Success #stdin #stdout 0s 6360KB
stdin
8
1798 1832
862 700
1075 1089
1568 1557
2575 1984
1033 950
1656 1649
1014 1473
stdout
6
0
2
4
7
1
5
1