题意:

对于一个1000*1000的Mushroom,

起点在(1,1)给定一个斜率和一个x,求由斜率和x所对应的直线构成的三角形内蘑菇的总值。

每个点的对应的值为(x+A)(y+B)

每个点都有一个相对于(1,1)的一个斜率我们就按照这个斜率的大小进行排序 大的放在后面

然后我们对于每个要查询的点的斜率的进行排序

采用离线的 方法去计算我们要求的东西这样我们对于每次查询都把小于他斜率的点扔进树状数组对应的x中就可以了

然后求和

#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
using namespace std;
const int maxn =+;
typedef long long LL; struct point
{
int x,y;
LL ans;
double p;
point(int cx=,int cy=,LL cans=,double cp=)
{
x=cx; y=cy; ans=cans; p=cp;
}
}s[maxn],sc[maxn];
bool cmpp(point a, point b)
{
return a.p<b.p;
}
bool cmpi(point a, point b)
{
return a.y<b.y;
}
LL C[];
int lowbit(int x)
{
return x&-x;
}
void add(int x,LL d)
{
while(x<=)
{
C[x]+=d; x+=lowbit(x);
}
}
LL sum(int x)
{
LL ret=;
while(x>)
{
ret+=C[x]; x-=lowbit(x);
}
return ret;
} int main()
{
int num=;
for(int i=; i<=;i++)
for(int j=; j<=; j++)
s[num++]=point(i,j,,1.0*j/i);
int cas;
sort(s,s+num,cmpp);
scanf("%d",&cas);
for(int cc =; cc<=cas; cc++)
{
LL A,B;
scanf("%I64d%I64d",&A,&B);
int m;
scanf("%d",&m);
for(int i=; i<m; i++){
int a,b,x;
scanf("%d%d%d",&a,&b,&x);
sc[i]=point( x,i,,1.0*b/a );
}
sort(sc,sc+m,cmpp);
int now=;
memset(C,,sizeof(C));
for(int i=; i<m; i++)
{
while(now<&&s[now].p<=sc[i].p){
add(s[now].x,1LL*(s[now].x+A)*(s[now].y+B));now++;
}
sc[i].ans=sum(sc[i].x);
}
sort(sc,sc+m,cmpi);
printf("Case #%d:\n",cc);
for(int i=; i<m; i++)
{
printf("%I64d\n",sc[i].ans);
}
} return ;
}

hdu5032 树状数组的更多相关文章

  1. HDU5032 -- Always Cook Mushroom 树状数组 14年北京网络赛

    题意:1000*1000的格子, 坐标为(1, 1) ~ (1000, 1000), 常数 A, B, 点(x,  y)权值为 (x + A) * (y + B), q次询问, 每次询问(0, 0) ...

  2. HDU5032 Always Cook Mushroom(树状数组&&离线)

    树状数组+询问离线.一个优化是需要的,就是先对1000*1000个点先排序,而不是每次都生成这1000*1000个点然后和询问一起排序,那样会tle. #include <iostream> ...

  3. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  4. bzoj1878--离线+树状数组

    这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...

  5. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

  7. BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]

    3529: [Sdoi2014]数表 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1399  Solved: 694[Submit][Status] ...

  8. BZOJ 3289: Mato的文件管理[莫队算法 树状数组]

    3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 2399  Solved: 988[Submit][Status][Di ...

  9. 【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组

    E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

随机推荐

  1. 抽屉之Tornado实战(4)--发帖及上传图片

    对于链接,点击获取标题时,本质发送ajax请求,然后去链接抓取信息,发布又是发送ajax请求 发布信息,还要有发布者的信息,并在信息表需要记录发布者的用户名,发布者的头像,发布者的id,而这些信息可以 ...

  2. LeetCode 226 Invert Binary Tree 解题报告

    题目要求 Invert a binary tree. 题目分析及思路 给定一棵二叉树,要求每一层的结点逆序.可以使用递归的思想将左右子树互换. python代码 # Definition for a ...

  3. python3安装ipython 过程以及问题

    由于需要再python3的环境下运行demo,因此安装了python3的ipython notebook,过程如下: sudo pip3 install ipython[all]这样就安装了pytho ...

  4. python pip install 报错TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' Command "python setup.py egg_info" failed with error code 1 in

    pip install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl ...

  5. 【JMeter】【接口测试】csv参数化,数据驱动,自动化测试

    csv参数化,数据驱动   首先我们要有一个接口测试用例存放的地方,我们这里用EXCEL模板管理,里面包含用例编号.入参.优先级.请求方式.url等等. 1:新建一个txt文件,命名为sjqd,后缀名 ...

  6. finecms如何控制调用子栏目的数量

    finecms如何控制调用子栏目的数量?比如只要调用栏目id为23下的3个子栏目要怎么写?我们把num=3放后面不能实现,放在return前面就可以了,原来是顺序的问题,return只能放最后 {li ...

  7. iOS App让自己的应用在其它应用中打开列表中显示

    像百度网盘等应用,里面的文件打开时,都能够通过以下应用再打开文件.以下红色框框内的我的jpg就是我做的一个样例. 由于样例没有提供Icon,所以显示的是默认icon.   以下就是这样例的主要步骤和代 ...

  8. shell脚本编写实例

    实际案例 1.判断接收参数个数大于1 [ $# -lt 1 ] && echo "至少需要一个参数" && { echo "我要退出了.. ...

  9. 007-js中的Array常用方法

    原文:http://www.runoob.com/jsref/jsref-obj-array.html 摘要常用方法 const array=new Array(); // 1 增加元素 // 1.1 ...

  10. 微信小程序github源码

    https://github.com/justjavac/awesome-wechat-weapp https://www.cnblogs.com/tuyile006/p/6268961.html h ...