题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1541

题意

求每个等级的星星有多少个

当前这个星星的左下角 有多少个 星星 它的等级就是多少

和它同一水平线的左边的星星 以及 同一竖直线的下边的星星也算在内

思路

因为题目给出的x y 坐标 是按照 以 y 为第一关键词 x 为第二关键词 排序后给出的

那么 对于当前的星星来说,在它之前给出的星星中,都是在它下边的

所以 我们就可以不用管 Y 坐标 只用X 坐标

形成一个序列 就是求这个序列的 所有逆序对的个数

树状数组

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 32000 + 5;
const int MOD = 1e9 + 7; int a[maxn];
int sum[maxn]; int lowbit(int x)
{
return x & (-x);
} int Sum(int n)
{
int ans = 0;
while (n > 0)
{
ans += a[n];
n -= lowbit(n);
}
return ans;
} void add(int x)
{
while (x <= maxn)
{
a[x]++;
x += lowbit(x);
}
} int main()
{
int n;
while (~scanf("%d", &n))
{
CLR(sum);
CLR(a);
int x, y;
for (int i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
sum[Sum(++x)]++;
add(x);
}
for (int i = 0; i < n; i++)
printf("%d\n", sum[i]);
}
}

HDU - 1541 Stars 【树状数组】的更多相关文章

  1. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  2. hdu 1541 (基本树状数组) Stars

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ...

  3. HDU 1541 STAR(树状数组)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  4. Stars(树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=1541 Stars Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  5. hdu1541 Stars 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意就是统计其左上位置的星星的个数 由于y已经按升序排列,因此只用按照x坐标生成一维树状数组 ...

  6. HDU 2838 (DP+树状数组维护带权排序)

    Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ...

  7. HDU 2689Sort it 树状数组 逆序对

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. POJ-2352 Stars 树状数组

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...

  9. Stars(树状数组或线段树)

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...

  10. hdu 4046 Panda 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...

随机推荐

  1. django常用第三方app大全

    djangoapp 资源大全 最近经常在这个版面看到Django相关扩展的介绍,而其一个扩展写一个帖子,觉得没太必要吧. 以前整理的django资源列表,从我的wiki上转过来的. 要找django资 ...

  2. matlab修改文件名和删除某类文件

    matlab修改多级文件夹路径下的文件名: % %%%%%%%%%%%%%%批量修改文件名一级文件夹 \路径下直接为文件 % close all;clear all;clc; % path='G:\1 ...

  3. tomcat下配置https方式

    [本地HTTPS]①.<Connector SSLEnabled="true" clientAuth="false" keystoreFile=" ...

  4. js ioc 实现

    var ar=[]; var o1={ id:'o1', o2:null } ar.push(o1); var o2={ id:'o2', o1:null } ar.push(o2) var ioc= ...

  5. 微信小程序 - 考试状态不同显示

    未开考 .已交卷. 考试中 .考试结束 #ddd      #f00     #ff0    默认禁用色 禁用的button仅有style起作用,四个状态,通过wx:if ... elif ... e ...

  6. WeakReference &&reference quene &&GC

    在了解WeakReference之前,先给出一段简单的代码: public class WeakReferenceTest {public static void main(String[] args ...

  7. vue.js+koa2项目实战(一)创建项目和elementUI配置

    前端采用vuex+element-ui: 后端采用koa2+restfulAPI+sequlize: (一)项目介绍 宠物社区 1.社区 2.好友 3.说说 4.宠粮 5.健康 (二)项目框架 1.V ...

  8. centos6.5下载

    1.64位系统 http://mirrors.163.com/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso http://mirrors. ...

  9. windows ce.net开发概述

    依据开发所处的层次以及开发工具的不同,能够将嵌入式系统开发分为系统开发和应用开发. 系统开发所涉及的内容包含三个方面:系统定制.驱动程序开发.操作系统一致(BSP开发). 一系统开发 (1)      ...

  10. 学写jQuery插件开发方法

    jQuery如此流行,各式各样的jQuery插件也是满天飞.你有没有想过把自己的一些常用的JS功能也写成jQuery插件呢?如果你的答案是肯定的,那么来吧!和我一起学写jQuery插件吧!   很多公 ...