记录编号 582492 评测结果 AAAAAAAAAA
题目名称 [POJ 2352]数星星 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2023-09-15 19:43:58 内存使用 0.65 MiB
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 5e4+10;
  4. int n;
  5. int ans[N],c[N];
  6. //树状数组
  7. struct made{
  8. int x,y;
  9. bool operator <(const made& z)const{
  10. if(x == z.x)return y < z.y;
  11. else return x < z.x;
  12. }//重载<运算符
  13. }a[N];
  14. void add(int x,int z){
  15. while(x <= 32001){//!!!
  16. c[x] += z;
  17. x += x&-x;
  18. }
  19. return;
  20. }
  21. int ask(int x){
  22. int ss = 0;
  23. while(x > 0){
  24. ss += c[x];
  25. x -= x&-x;
  26. }
  27. return ss;
  28. }
  29. int main(){
  30. freopen("starcount.in","r",stdin);
  31. freopen("starcount.out","w",stdout);
  32. scanf("%d",&n);
  33. for(int i = 1;i <= n;i++){
  34. scanf("%d%d",&a[i].x,&a[i].y);
  35. a[i].x++,a[i].y++;
  36. }
  37. sort(a+1,a+1+n);
  38. for(int i = 1;i <= n;i++){
  39. ans[ask(a[i].y)]++;
  40. add(a[i].y,1);
  41. }
  42. for(int i = 0;i < n;i++)
  43. printf("%d\n",ans[i]);
  44. return 0;
  45. }