[POJ2352] Stars(树状数组)
先按照下标x排序,然后依次把y加入树状数组,边加入边统计即可。
注意下标re从零开始,需+1s
——代码
# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <cmath>
# include <vector>
# include <map>
# include <queue>
# include <cstdlib>
# include <algorithm>
# define MAXN
using namespace std; inline int get_num() {
int k = , f = ;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -;
for(; isdigit(c); c = getchar()) k = k * + c - '';
return k * f;
} int n;
int c[MAXN], ans[MAXN];
struct node
{
int a, b;
}p[MAXN]; inline bool cmp(node x, node y)
{
return x.a < y.a || (x.a == y.a && x.b < y.b);
} inline int lowbit(int x)
{
return x & -x;
} inline int query(int x)
{
int ans = ;
for(; x; x -= lowbit(x)) ans += c[x];
return ans;
} inline void add(int x)
{
for(; x <= ; x += lowbit(x)) c[x] += ;
} int main()
{
int i, t;
n = get_num();
for(i = ; i <= n; i++)
{
p[i].a = get_num() + ;
p[i].b = get_num() + ;
}
sort(p + , p + n + , cmp);
for(i = ; i <= n; i++)
{
t = query(p[i].b);
add(p[i].b);
ans[t]++;
}
for(i = ; i < n; i++) printf("%d\n", ans[i]);
return ;
}
[POJ2352] Stars(树状数组)的更多相关文章
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- POJ2352 Stars 树状数组
emm,ssy说可以直接CDQ分治...%%%但是注意到y是有序的,所以可以直接求一下前缀和就行了. 题干: Astronomers often examine star maps where sta ...
- POJ2352 Stars [树状数组模板]
题意:输入一n颗星星的x,y坐标,给定判断level的标准,即某颗星星左下边(不高于它,不超过他,相当于以他为基准的第三象限)星星的数目为level, 输出level从0到n的星星个数. //poj2 ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
- Stars(树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=1541 Stars Time Limit: 2000/1000 MS (Java/Others) Memor ...
- Stars(树状数组单点更新)
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- HDU-1541 Stars 树状数组
题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x& ...
- poj2352(树状数组)
题目链接:https://vjudge.net/problem/POJ-2352 题意:在直角坐标系中给出n个点的 (x,y),(0<=x,y<=32000),定义每个点的level为(x ...
- POJ 2352 && HDU 1541 Stars (树状数组)
一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...
- hdu1541 Stars 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...
随机推荐
- 用户名密码登录小程序及input与raw_input区别。
一.此次程序需要实现: 1.设定固定的用户名密码 2.用户名密码输入正确打印登录正确信息 3.仅仅运行三次登录 二.本次使用的python版本为: Windows下版本号: C:\Users\dais ...
- 微信环境支付宝服务窗环境app手机浏览器pc端混合判断
//微信环境 if(userAgent.match(/micromessenger/) == 'micromessenger'){ }//支付宝服务窗环境else if(userAgent.match ...
- AJPFX关于对集合中的元素删除操作和注意点
import java.util.ArrayList;import java.util.Iterator;import java.util.List; public class ForeTest2 { ...
- BeanUtils.copyProperties(productInfo, productInfoVO);
一:spring的工具类方法:BeanUtils.copyProperties(orderMasterDTO, orderMasterDO); 作用:将orderMasterDTO对象中的属性值,赋值 ...
- python中 import 和from ... import 的区别
先看一个例子: 我自定义的一个moudle,里面有一个方法sayhi,还有一个变量version#!/usr/bin/env python # coding=utf-8 # Filename: mym ...
- 【HEVC帧间预测论文】P1.4 Motion Vectors Merging: Low Complexity Prediction Unit Decision
Motion Vectors Merging: Low Complexity Prediction Unit Decision Heuristic for the inter-Prediction o ...
- SVM-支持向量机 学习 1
参考 https://zhuanlan.zhihu.com/p/42334376 https://blog.csdn.net/liugan528/article/details/79448379 ht ...
- 【整理】iview Tree数据格式问题,无限递归树处理数据
iview Tree数据格式问题,无限递归树处理数据 https://juejin.im/post/5b51a8a4e51d455d6825be20
- js 数组元素排序?
Part.1 sort 方法 js 有自带排序方法 sort(), 默认 升序 排列 如: data() { return { arr: [1,3,2,5,6,8,7,4,9] } }, 控制台如 ...
- 弹跳加载动画特效Bouncing loader
一款非常常用的css 加载动画,这款CSS3 Loading动画主要由几个小球通过规律的上下跳动,渐隐渐显而成,效果十分生动.流畅.兼容IE8以上,尤其适合在移动端中使用,基本代替了图片实现加载的效果 ...