绝对大坑。千万记住树状数组0好下标位置是虚拟节点。详见大白书P195。其实肉眼看也能得出,在add(有的也叫update)的点修改操作中如果传入0就会死循环。最后TLE。所以下标+1解决问题。上代码!

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <cctype>
#include <cmath>
using namespace std; const int V = + ;
const int M = + ;
int C[V], res[M]; int lowbit (int x) {
return x & -x;
} int sum (int x) {
int ret = ;
while (x > ) {
ret += C[x]; x -= lowbit(x);
}
return ret;
} void add (int x, int d) {
while (x <= V) {
C[x] += d; x += lowbit(x);
}
} int main () {
int n, x, y;
while (~scanf("%d", &n)) {
memset(C, , sizeof(C));
memset(res, , sizeof(res)); for (int i = ; i < n; ++ i) {
scanf ("%d %d", &x, &y);
res[sum(x + )] ++;
add(x + , );
}
for (int i = ; i < n; ++ i) {
printf ("%d\n", res[i]);
}
}
return ;
}

【HDU1514】Stars(树状数组)的更多相关文章

  1. POJ-2352 Stars 树状数组

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

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

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

  3. Stars(树状数组)

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

  4. Stars(树状数组单点更新)

    Astronomers often examine star maps where stars are represented by points on a plane and each star h ...

  5. HDU-1541 Stars 树状数组

    题目链接:https://cn.vjudge.net/problem/HDU-1541 题意 天上有许多星星 现给天空一个平面坐标轴,统计每个星星的level, level是指某一颗星星的左下角(x& ...

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

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

  7. hdu1541 Stars 树状数组

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

  8. Stars(树状数组+线段树)

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

  9. POJ2352 Stars 树状数组

    emm,ssy说可以直接CDQ分治...%%%但是注意到y是有序的,所以可以直接求一下前缀和就行了. 题干: Astronomers often examine star maps where sta ...

  10. POJ2352 Stars [树状数组模板]

    题意:输入一n颗星星的x,y坐标,给定判断level的标准,即某颗星星左下边(不高于它,不超过他,相当于以他为基准的第三象限)星星的数目为level, 输出level从0到n的星星个数. //poj2 ...

随机推荐

  1. samsungGalaxyS4USB驱动

    http://www.samsung.com/cn/support/usefulsoftware/KIES/JSP

  2. c语言结构体数组定义的三种方式

    struct dangdang { ]; ]; ]; int num; int bugnum; ]; ]; double RMB; int dangdang;//成员名可以和类名同名 }ddd[];/ ...

  3. WPF - XAML如何引入名字空间

    WPF 的XAML引入名字空间的概念,经常容易让人混淆.如何引入名字空间,并且在XAML中调用其中的类,下面给一个简单的介绍. 比如我们有一个Hepler类. namespace Wheat.PIMS ...

  4. AllocConsole

    #include<iostream> using namespace std; AllocConsole(); freopen("CONIN$", "r+t& ...

  5. Android自定义控件(四)——让每一个Activity UI都具有弹性

    前面我们已经介绍了如何让你的ScrollView,ListView具有弹性, 今天,我们在前面的基础上,做一下适当的修改,让那些既不是ScrollView,也不是ListView的Activity页面 ...

  6. Node.js 之 express 入门 ejs include公共部分

    1. 直接进入express安装 因为之前有一篇文章我已经讲过怎么安装node了 而网上的教程也是非常多.所有直接进入到express.教程简陋 由于我比较笨 所有只要写到我自己明白就行. 这里有个教 ...

  7. ibatis之##与$$的 使用

    /** 主要讲一下ibatis中$$的使用: 是为了传递参数; 参数一定在Action层用''包裹起来: */ List <SysRole> userList= systemService ...

  8. asp.net 正则表达式

    在平时的开发中常常用到替换法:  普通的字符串替换可以使用string.replace(string,string),但是比较难解决HTML文本的替换. 经我几番查找,终也找出解决办法:正则匹配替换. ...

  9. .net后台 Silverlight 页面 动态设置 ASPX 页面 控件的Margin值(位置设置)

    silverlight后台代码:using System.Windows.Browser;public Page1(){HtmlPage.RegisterScriptableObject(" ...

  10. Jquery对选取到的元素显示指定的长度,对于的字符串用“...”显示

    $(function() { $(".video_name").each(function() { var s = $(this).text(); $()); }); }); fu ...