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. 常用快捷键及eclipise快捷键

    win+R 运行...win+D 桌面win+E 打开我的电脑win+F 搜索 ctrl+D删除光标所在行

  2. The partial charge density (1)

    ============================================================================================= The pa ...

  3. 学习C++50条忠告

    1.把C++当成一门新的语言学习: 2.看<Thinking In C++>,不要看<C++变成死相>: 3.看<The C++ Programming Language ...

  4. Linux配置Hadoop 常用的命令

    uname -a 看主机位数 ip a 看IP地址 vi /etc/sysconfig/network 改主机的名字 vi /etc/hosts 改映射关系 vi /etc/sysconfig/net ...

  5. Our Journey of Xian Ends

    Our Journey of Xian Ends https://nanti.jisuanke.com/t/18521 262144K   Life is a journey, and the roa ...

  6. 没有无线路由,如何让手机使用电脑的网络xyytit

    前言: 智能手机已经越来越普遍,但国内的无线网络的步伐还是没有跟上智能机的脚步.纵使3G,4G已经相继推出,但国内的资费价格着实有点不接地气,所以无线wifi无疑是智能机使用最多的.各大软件上.设备商 ...

  7. python之面向对象之反射运用

    先看下hasattr和getattr在反射中的用法 import sys class apache(object): def __init__(self,tcp): self.tcp = tcp de ...

  8. (hash map)Two Sum, sorted(排序+双指针)closest,小于或大于的对数,组成不同的对数

    原版 sorted [抄题]: [思维问题]: 存sum - nums[i](补集),若出现第二次则调出 [一句话思路]: hashmap中,重要的数值当做key,角标当做value. [画图]: [ ...

  9. Centos7 安装MySQL8.0.15

    1.删除原有的mariadb,不然mysql装不进去 mariadb-libs-5.5.52-1.el7.x86_64 rpm -qa|grep mariadb rpm -e --nodeps mar ...

  10. sqlserver 日期格式化

    Sql Server 中一个非常强大的日期格式化函数Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSelect CONVE ...