题目大意

http://www.lydsy.com/JudgeOnline/problem.php?id=2850

题解

对于每个人,我们发现它能够接受的巧克力中

如果对参数分别讨论,那么一定是一个连续的区间

所以我们利用K-D划分维度,然后直接搜就好了

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline ll min(ll a,ll b,ll c){return min(a,min(b,c));}
inline ll max(ll a,ll b,ll c){return max(a,max(b,c));}
const int maxn = 50010;
const int dem = 2;
struct Node{
ll pos[2],sum,val;
ll minn[2],maxx[2];
Node *ch[2];
void update(){
minn[0] = min(pos[0],ch[0]->minn[0],ch[1]->minn[0]);
maxx[0] = max(pos[0],ch[0]->maxx[0],ch[1]->maxx[0]);
minn[1] = min(pos[1],ch[0]->minn[1],ch[1]->minn[1]);
maxx[1] = max(pos[1],ch[0]->maxx[1],ch[1]->maxx[1]);
sum = val + ch[0]->sum + ch[1]->sum;
}
}*null,*root;
Node T[maxn],aNoUseNode;
inline void init(){
null = &aNoUseNode;null->ch[0] = null->ch[1] = null;
null->sum = null->val = 0;
null->minn[0] = 1LL<<60;null->maxx[0] = -(1LL<<60);
null->minn[1] = 1LL<<60;null->maxx[1] = -(1LL<<60);
}
int split[maxn],now;
inline bool cmp(const Node &a,const Node &b){
return a.pos[split[now]] < b.pos[split[now]];
}
Node *build(int l,int r,int s){
if(l > r) return null;
int mid = (l+r) >> 1;
split[now = mid] = s % dem;
nth_element(T+l,T+mid,T+r+1,cmp);
Node *p = &T[mid];
p->ch[0] = build(l,mid-1,s+1);
p->ch[1] = build(mid+1,r,s+1);
p->update();return p;
}
ll a,b,c;
inline bool judge1(Node *p){
return (a*p->minn[0] + b*p->minn[1] < c)
&& (a*p->minn[0] + b*p->maxx[1] < c)
&& (a*p->maxx[0] + b*p->minn[1] < c)
&& (a*p->maxx[0] + b*p->maxx[1] < c);
}
inline bool judge2(Node *p){
return (a*p->minn[0] + b*p->minn[1] >= c)
&& (a*p->minn[0] + b*p->maxx[1] >= c)
&& (a*p->maxx[0] + b*p->minn[1] >= c)
&& (a*p->maxx[0] + b*p->maxx[1] >= c);
}
ll query(Node *p){
if(p == null) return 0;
ll ret = 0;
if(a*p->pos[0] + b*p->pos[1] < c) ret += p->val;
if(judge1(p->ch[0])) ret += p->ch[0]->sum;
else if(!judge2(p->ch[0])) ret += query(p->ch[0]);
if(judge1(p->ch[1])) ret += p->ch[1]->sum;
else if(!judge2(p->ch[1])) ret += query(p->ch[1]);
return ret;
}
int main(){
init();
ll n,m;read(n);read(m);
for(int i=1;i<=n;++i){
read(T[i].pos[0]);read(T[i].pos[1]);
read(T[i].val);T[i].ch[0] = T[i].ch[1] = null;
T[i].update();
}
root = build(1,n,1);
while(m--){
read(a);read(b);read(c);
printf("%lld\n",query(root));
}
getchar();getchar();
return 0;
}

最新文章

  1. ahjesus web动态icon
  2. Atitit &#160;从 RGB 到 HSL 或 HSV 的转换
  3. [LintCode] Minimum Size Subarray Sum 最小子数组和的大小
  4. spring事物配置,声明式事务管理和基于@Transactional注解的使用
  5. 【jQuery】: 定时刷新页面
  6. centos6.3 + db2v9.7的数据库移行
  7. ionic icons and splash
  8. js中的null和undefined
  9. Android选项卡TabHost方式实现
  10. HDU 1025 Constructing Roads In JGShining&#39;s Kingdom(DP+二分)
  11. Mongodb在Windows下安装及配置 【转】
  12. deep learning in nlp 资料文献
  13. [Android学习笔记]jackson库的使用
  14. SpringMVC框架学习笔记(3)——controller配置汇总
  15. Error: Cannot fit requested classes in a single dex file (# methods: 149346 &gt; 65536)
  16. pc端网页,移动端网页(andorid、ios)离开页面做一个时间存储
  17. LDAP&amp;IMPLEMENTATION
  18. DevExpress.Mvvm.Free
  19. MarkDown学习——基础用法
  20. 怎样从外网访问内网WebSphere?

热门文章

  1. Java编码辅助工具:Mapstruct—— Java对象转换框架
  2. android7.x Launcher3源代码解析(3)---workspace和allapps载入流程
  3. VIM中保存编辑的只读文件
  4. Java提高(二)---- HashTable
  5. VxWorks启动过程具体解释(下)
  6. iOS中数组遍历的方法及比較
  7. iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)
  8. PDO:: 数据访问抽象层 ? :
  9. vue 向后台提交数据
  10. 搭建SVN服务器详细教程