题意:

对于一个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. 《linux 计划任务》- cron

    一:什么是计划任务 - 你给手机定了一个闹钟,每天的 7:00 会准时响铃叫你起床,这实际上就是一个计划任务 - 所谓定时任务,就是在已经定好的特定时间去执行的事情. - Cron是一个[守护程序]用 ...

  2. mysql插入一条记录时有自增id怎么办

    ①可以把id的值设置为null或者0,这样子mysql都会自己做处理 ②手动指定需要插入的列,不插入这一个字段的数据!

  3. Python开发【笔记】:asyncio 定时器

    asyncio 定时器 实现: import asyncio class Timer: def __init__(self, timeout, callback): self._timeout = t ...

  4. MapStruct

    一.Object mapping 的技术分类: 运行期 反射调用set/get 或者是直接对成员变量赋值 . 该方式通过invoke执行赋值,实现时一般会采用beanutil, Javassist等开 ...

  5. windows无法安装到这个磁盘。选中的磁盘采用GPT分区形式 Windows 检测到 EFI 系统分区格式化为 NTFS。将 EFI 系统分区个数化为 FAT32,然后重新启动安装

    win10安装问题解决 问题 1.windows无法安装到这个磁盘.选中的磁盘采用GPT分区形式 解决方法: 1.bios,更改 uefi/legacy boot 为ueei only 后面可以安装了 ...

  6. vue.js安装问题

    1.安装:npm install --global vue-cli 2.创建项目:vue init webpack my-project npm WARN deprecated browserslis ...

  7. 学习Shell(一)

    查看 Shell Shell 是一个程序,一般都是放在/bin或者/user/bin目录下,当前 Linux 系统可用的 Shell 都记录在/etc/shells文件中./etc/shells是一个 ...

  8. 向github提交代码总是要输入用户名密码

    在命令行输入命令: $ git config --global credential.helper store 这一步会在用户目录下的.gitconfig文件最后添加: [credential]    ...

  9. throws和throw的区别

    throws是声明在方法上,告诉调用者这个方法可能会出现的问题.格式  :   方法()   throws  自定义异常类(异常类)    就是在这个方法里面会出问题时,new  throw时,    ...

  10. ansible-playbook 快速入门

    管理用户密码: --- - hosts: test tasks: - name: changed password shell: echo root:123456 | chpasswd remote_ ...