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

给定一个1000x1000的点阵,m组询问,每次询问一个由(0,0)、(x,0)点一以及从原点出发的方向向量(a,b)构成的直角三角形包围的点的权值和。

先把1000x1000个点离线出极角关系,然后对m个询问按极角排序,不停add,遇到询问的极角就query一次前缀和

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
int A,B,m;
struct point{
int x,y;
LL ans;
double p;
}s[1000005],sc[100005];
bool cmpp(point a,point b)
{
return a.p < b.p;
}
bool cmpid(point a,point b)
{
return a.y < b.y;
}
LL bit[1005];
void add(int x,LL v)
{
for(int i = x;i <= 1000;i += (i&-i))
bit[i] += v;
}
LL query(int x)
{
LL ans = 0;
for(int i = x;i >= 1;i -= (i&-i))
ans += bit[i];
return ans;
}
int main(){
int _,cnt = 0,cas = 1,x,a,b;
RD(_);
for(int i = 1;i <= 1000;++i)
for(int j = 1;j <= 1000;++j){
s[cnt++] = (point){i,j,0,1.0*j/i};
}
sort(s,s+cnt,cmpp);
while(_--){
RD2(A,B);
RD(m);
for(int i = 0;i < m;++i){
RD2(a,b);RD(x);
sc[i] = (point){x,i,0,1.0*b/a};
}
sort(sc,sc+m,cmpp);
clr0(bit);
int now = 0;
for(int i = 0;i < m;++i){
while(s[now].p <= sc[i].p){
add(s[now].x,(LL)(s[now].x + A)*(s[now].y + B));
now++;
}
sc[i].ans = query(sc[i].x);
}
sort(sc,sc+m,cmpid);
printf("Case #%d:\n",cas++);
for(int i = 0;i < m;++i)
//cout<<sc[i].ans<<endl;
printf("%I64d\n",sc[i].ans);
}
return 0;
}

hdu 5032 不易发觉的树状数组的更多相关文章

  1. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  2. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  3. HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                         ...

  4. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

  5. hdu 5592 ZYB's Game 树状数组

    ZYB's Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=55 ...

  6. HDU 1394 Minimum Inversion Number (树状数组求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多 ...

  7. HDU 5877 Weak Pair(树状数组)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5877 [题目大意] 给出一棵带权有根树,询问有几对存在祖先关系的点对满足权值相乘小于等于k. [题 ...

  8. HDU 2689 Sort it【树状数组】

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

  9. HDU 5517---Triple(二维树状数组)

    题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...

随机推荐

  1. one by one 项目 part 2

    在网上百度了一下mySQL常用语句 ,整理如下: 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3. ...

  2. 微擎系统 微信支付 get_brand_wcpay_request:fail

    支付授权目录问题,有一个是域名加app的

  3. maven tomcat7 远程热部署

    在maven项目开发中,一般推荐使用jetty进行开发调试.但是在项目发布的时候要求使用tomcat7作为发布服务器,为此在maven中配置了tomcat7插件,以支持项目在外部tomcat7进行远程 ...

  4. 本地Maven库添加SQLServer2012 sqljdbc4.jar

    最近又开始搞Java项目了,学习下maven用法(ant时代真的过去了啊?) 选了个国内的小框架来做,有个小需求,客户需要用牛逼哄哄的SQLServer,新版的比如SQLServer2012的sqlj ...

  5. 两个onCreate方法?你真的了解onCreate()么?

    Activity的onCreate方法一直是我们编写一个activity最先重载的方法.细心的小伙伴在编写代码的时候回看到这样一幕: 咦,这里怎么会有两个onCreate提供给我们重载?选择困难症患者 ...

  6. Openvpn 日常问题解决

    一.Openven的在windows系统下的使用: 1.Openven客户端2.2.0:http://pan.baidu.com/s/1sjJij4T 安装好客户端软件后,将服务器下发的证书和配置文件 ...

  7. GridView,datalist添加序号列

    GridView添加序号列:这个是经常需要的一个功能 <asp:TemplateField HeaderText="序号"> <ItemTemplate> ...

  8. oracle JDeveloper学习

    1>oracle JDeveloper官方地址,官方的学习资源包括视频和教材,很全面,很多不知道从和入手. 2>oracle JDeveloper 12C 教程,一步步学习jdev,可以此 ...

  9. js深拷贝、浅拷贝

    浅拷贝: 只针对当前对象的属性进行拷贝,若当前对象的属性是引用类型时,这个不考虑,不进行拷贝.若属性是引用类型,拷贝后引用的是地址,如果进行更改,会影响拷贝的原对象属性. 深拷贝:针对当前对象的数据的 ...

  10. CodeSmith生成SQL Server视图的实体类脚本/对应的生成模板

    C#生成sql视图的实体类 using System;using System.Text;using CodeSmith.Engine;using SchemaExplorer;using Syste ...