题目链接

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. 80端口被屏蔽解决方法,80端口穿透之NAT端口映射技术

    介绍一种NAT端口映射技术应用,达到80端口穿透目的,解决80端口被屏蔽的问题,也是80端口被屏蔽解决方法中经常用到的. 80端口穿透类似80端口转发,因为80端口被屏蔽,在数据层面来说是不能直接访问 ...

  2. c# winform 最小化到托盘

    STEP1.添加托盘图标控件NotifyIcon(直接从工具箱中拖动添加即可) STEP2.添加(重写)窗口尺寸变动函数Form1_Resize private void Main_SizeChang ...

  3. doviceone- http组件进行webservice的POST请求

    var http = mm("do_Http"); http.method = "POST"; // GET | POST http.timeout = 100 ...

  4. python pandas相关知识点(练习)

    首先引入库文件,并进行数据读取 import pandas as pd import numpy as np data_Base=pd.read_csv("D:\\Exam_Test\\un ...

  5. ElasticSearch命令增加字段总结

    1.建立一个String类型的字段 curl -XPUT http://192.168.46.163:9200/t_risk_case/_mapping/t_risk_case?pretty -d ' ...

  6. 身份证实名认证接口调用实例(PHP)

    基于php的身份证实名认证接口调用代码实例,身份证实名认证接口申请:https://www.juhe.cn/docs/api/id/103 <!--?php // +-------------- ...

  7. koajs 项目实战(一)

    (一)koa 1.Koa(koajs)--  基于 Node.js 平台的下一代 web 开发框架 koa1 npm install koa -g npm install koa-generator ...

  8. OLR

    OLR:Oracle Local Registry 环境:11.2.0.3  RAC  RHEL6.5 It contains local node specific configuration re ...

  9. vs2010 assistx安装教程

    参照此篇教程. 安装目录你可能找不到,因为那些文件是系统隐藏文件,打开隐藏即可. 然后,将此.exe安装到上面的目录下,然后,还需要进行一个破解,即需要将从网上下载的补丁放进去. 把目录下的VA_X. ...

  10. VueJS样式绑定v-bind:class

    class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v-bind 来设置样式属性. Vue.js v-bind 在处理 class 和 style 时, 专门增强了它 ...