UESTC 1584
2024-08-31 15:22:10
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 ;
}
最新文章
- os.path 大全
- 黑马程序员——File笔记读,写,复制
- DNS(二)之构建域名解析缓存
- Checkstyle 简介 以及各版本下载地址
- UVa 100 - The 3n + 1 problem(函数循环长度)
- PHP发送邮件。
- ServiceStack简介
- rsync 文件校验及同步原理及rsync server配置
- 在openwrt上初体验PostgreSQL数据库
- jquery删除动态增加的li
- 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;.
- min-max容斥
- Prometheus监控学习笔记之Prometheus 2.0 告警规则介绍
- file标签 - 图片上传前预览 - FileReader &; 网络图片转base64和文件流
- zabbix通过自动发现tomcat应用端口监控连接数
- MSSQL内存架构及管理
- Linux下的压缩文件剖析 (tar/gzip的区别)
- pd.read_csv操作读取分隔符csv和text文件
- [Data Structure] Linked List Implementation in Python
- 解释Spring中IOC, DI, AOP