hdu 5032 不易发觉的树状数组
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 不易发觉的树状数组的更多相关文章
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number ...
- HDU 5862 Counting Intersections (树状数组)
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...
- 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 ...
- HDU 1394 Minimum Inversion Number (树状数组求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多 ...
- HDU 5877 Weak Pair(树状数组)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5877 [题目大意] 给出一棵带权有根树,询问有几对存在祖先关系的点对满足权值相乘小于等于k. [题 ...
- HDU 2689 Sort it【树状数组】
Sort it Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 5517---Triple(二维树状数组)
题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...
随机推荐
- zabbix3.2的server和zabbix-agent2.2怎么监控MySQL的办法
zabbix官方支持监控MySQL,但直接使用默认的模板是不可用的,还需要经过额外的设置才可以使用.如果只需要对mysql数据库做简单的监控,zabbix自带的模板完全能够满足要求:如果有更高的需求那 ...
- Spring集成Redis使用注解
转载:http://blog.csdn.net/u013725455/article/details/52129283 使用Maven项目,添加jar文件依赖: <project xmlns=& ...
- Golang之时间、日期类型
孤身只影的一直小地鼠,艰难的走在路上 package main import ( "fmt" "time" ) //获取时间的格式 func testTime( ...
- xmlhttp
File an issue about the selected textFile an issue about the selected text XMLHttpRequest Living Sta ...
- c3p0数据源配置
Xml代码 <c3p0-config> <default-config> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数.Default: --> ...
- geoserver 通过代码实现发布地图服务
GeoServer:代码实现批量发布地图服务 利用GeoServer发布WCS服务,那么如果我有很多数据需要进行发布,这样利用GeoServer提供的UI界面进行操作显然很不显示.那能不能利用GeoS ...
- Laravel - Opening Multiple Projects
On this page: Basics Opening multiple projects Deleting a project from view Important notes Basics P ...
- c++11日志练习
/************************************************************** 技术博客 http://www.cnblogs.com/itdef/ ...
- 关于IBatisNet的配置文件中数据库连接字符串加密处理
我们通常在IBatisNet配置文件 properties.config 加入数据库连接字符串.数据库连接字符串直接放在里面,没有被加密,很不安全.如果我们把 properties.config 文件 ...
- CSS 关键的基础知识
今晚看了 百度传课 一门关于CSS的课程, 感觉不错, 随手记了点儿笔记, 供以后查阅. =================================================== pos ...