http://acm.uestc.edu.cn/#/problem/show/1584

Washi与Sonochi的约定

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 131072/131072KB (Java/Others)

Submit  Status
Sonochi,明年再一起看烟花。——WashioSumi

为了实现和Sonochi的约定,Washi必须要打败眼前强大的怪物。
怪物分布在二维平面上,
某个怪物的rank被定义为x坐标不大于其x坐标,且y坐标不大于其y坐标的怪物的数量。(不含其自身)
Washi要你输出n行,每行一个整数,分别代表rank为0~n−1的怪物数量。

Input

输入第一行为一个正整数n,
接下来n行,第ii行两个整数xi、yi,表示一个怪物的坐标。
保证输入的坐标两两不同。

Output

包含n行,每行一个整数,第ii行的数代表rank为i−1i−1的怪物数量

Sample Input Sample Output
5
1 1
5 1
7 1
3 3
5 5
1
2
1
1

0

Hint

1≤n≤100000
1≤xi≤100000

1≤yi≤100000

树状数组+排序

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int ran[];
int vis[],n;
struct Node
{
int x,y;
}node[];
bool cmp(const Node &a,const Node &b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y<b.y;
}
int main()
{
scanf("%d",&n);
memset(vis,,sizeof(vis));
memset(vis,,sizeof(ran));
for(int i=;i<n;i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
}
sort(node,node+n,cmp);
for(int i=;i<n;i++)
{
int ans=;
for(int j=node[i].y;j;j-=(j&-j))
ans+=vis[j];
ran[ans]++;
for(int j=node[i].y;j<;j+=(j&-j))
vis[j]++;
}
for(int i=;i<n;i++)
{
printf("%d\n",ran[i]);
}
return ;
}

最新文章

  1. os.path 大全
  2. 黑马程序员——File笔记读,写,复制
  3. DNS(二)之构建域名解析缓存
  4. Checkstyle 简介 以及各版本下载地址
  5. UVa 100 - The 3n + 1 problem(函数循环长度)
  6. PHP发送邮件。
  7. ServiceStack简介
  8. rsync 文件校验及同步原理及rsync server配置
  9. 在openwrt上初体验PostgreSQL数据库
  10. jquery删除动态增加的li
  11. xml错误之cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element &#39;mvc:annotation-driven&#39;.
  12. min-max容斥
  13. Prometheus监控学习笔记之Prometheus 2.0 告警规则介绍
  14. file标签 - 图片上传前预览 - FileReader &amp; 网络图片转base64和文件流
  15. zabbix通过自动发现tomcat应用端口监控连接数
  16. MSSQL内存架构及管理
  17. Linux下的压缩文件剖析 (tar/gzip的区别)
  18. pd.read_csv操作读取分隔符csv和text文件
  19. [Data Structure] Linked List Implementation in Python
  20. 解释Spring中IOC, DI, AOP

热门文章

  1. dva基本用法
  2. 【图灵杯 J】简单的变位词
  3. JVM分代通俗解释
  4. hadoop-06-http服务
  5. ACM POJ 1146 ID Codes
  6. 【推荐系统实战】:C++实现基于用户的协同过滤(UserCollaborativeFilter)
  7. jquery操作select的各种方法
  8. Objects and values
  9. BZOJ 4551 HEOI 2016 树 (并查集)
  10. CUDA还未产出,又要出北洋多元统计习题集