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 ...
随机推荐
- mysql 建库建表建用户
1.创建数据库 create database school; 2.使用数据库 Use school; 3.创建用户 create user jame@localhost identified by ...
- knn手写识别
import numpy as np import operator import os #KNN算法 def knn(k,testdata,traindata,labels):#(k,测试样本,训练 ...
- Ubuntu下Anaconda3的安装
1)去https://www.anaconda.com/download/#download下载Anaconda安装文件(python3.6的版本). 2)进入到Anaconda3-5.0.1-Lin ...
- 'org.hibernate.SQLQuery' is deprecated
'org.hibernate.SQLQuery' is deprecated 在Hibernate5.2之后,SQLQuery已经被摒弃,改用NativeQuery代替了. 在Hibernate中使用 ...
- 解决Lightmap在PC上与ios和Android上表现不同的问题
Lightmap在PC上与android和ios的区别以及解决方法 1. 问题描述 相信很多人碰到过Lightmap的一些问题: 烘培好Lightmap之后,在PC上看起来相当给力,而打包成ios或 ...
- 转)Ubuntu14安装wireshark进行抓包
转自:http://jingyan.baidu.com/article/c74d60009d992f0f6a595de6.html 背景: ubuntu14.04/64位 为了抓包和分析包 安装过程: ...
- 【校招面试 之 C/C++】第6题 C++深拷贝与浅拷贝
1.两个的区别(1)在未定义显示拷贝构造函数的情况下,系统会调用默认的拷贝函数——即浅拷贝,它能够完成成员的一一复制.当数据成员中没有指针时,浅拷贝是可行的: 但当数据成员中有指针时,如果采用简单的浅 ...
- Windows10电脑安装macOS Mojave系统的方法(最新版系统,含超详细步骤截图)
一.环境及准备工作 1.主机系统:本人系统是Windows10家庭中文版 2.虚拟机软件:VMware Workstation 14 Pro 虚拟机版本号:14.1.1 build-7528167 虚 ...
- Debian Buster 配置 Laravel 运行环境(nginx + redis + supervisor)
1 目标 将开发完成的 Laravel 项目布署于 Debian 之上.由于项目要求使用 horizon 官方扩展,要求 PHP7.1+,故采用 Debian buster (下一版) 2 材料 IP ...
- 项目管理心得:一个项目经理的个人体会、经验总结(zz)
本人做项目经理工作多年,感到做这个工作最要紧的就是要明白什么是因地制宜.因势利导,只有最合适的,没有什么叫对的,什么叫错的,项目经理最忌讳 的就是完美主义倾向,尤其是做技术人员出身的,喜欢寻找标准答案 ...