题意:

对于一个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 ;
}

最新文章

  1. Python In Action:二、 最小的GUI程序:麻雀虽小,五脏俱全
  2. torrent
  3. Hibernate一对一关联映射配置
  4. map 与 unordered_map
  5. 【项目经验】 Html Select 遇上 Easyui
  6. PHP实战-文章发布系统学习记录
  7. POJ 2823 Sliding Window 再探单调队列
  8. tableView嵌套collectionView
  9. MAC下安装automake autoconf工具
  10. 【转】Linux Shell脚本面试25问
  11. (转)fiddler实现手机抓包的基础设置问题
  12. webpack打包体积优化
  13. [20170916]sqlplus set array最小2补充.txt
  14. InstallShield2015制作安装包----------卸载后删除安装目录和文件
  15. 【转】让你彻底搞懂websocket
  16. Oracle学习笔记(八)
  17. PHP-----PHP程序设计基础教程----第四章数组
  18. 不再为命名而苦恼!使用 MSTestEnhancer 单元测试扩展,写契约就够了
  19. 从一个子视图或者一个View中刷新其他UITableView
  20. hiho一下 第一周 最长回文子串

热门文章

  1. LeetCode 888 Fair Candy Swap 解题报告
  2. 【PyQt5-Qt Designer】浅谈关闭窗口
  3. XSL常用用法语句
  4. node2vec应用记录
  5. NOIP观光公交
  6. oracle中nvarchar2()和varchar2()的区别
  7. 【Loadrunner】Loadrunner 手动关联技术
  8. mysql 初识sql语句
  9. chkdsk 命令对Raid盘检测和查错、修复
  10. linux中 /dev/null命令