Bzoj4822 [Cqoi2017]老C的任务
同样没题面
写完以后的感想是:我™都干了点啥。
正解是扫描线+树状数组
Bzoj1935 [SHOI2007]Tree 园丁的烦恼
↑差不多是原题。
然而……我写了K-Dtree
思维江化啊
幸好Bzoj的评测是计算总时间而不是单点时间的,让我得以卡过去233
1 #include<algorithm> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 #include<vector> 7 #define LL long long 8 using namespace std; 9 const int INF=1e9+7; 10 const int mxn=100011; 11 LL read(){ 12 LL x=0,f=1;char ch=getchar(); 13 while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();} 14 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} 15 return x*f; 16 } 17 int n,m; 18 struct node{ 19 int l,r; 20 int d[2]; 21 int mn[2],mx[2]; 22 LL v,smm; 23 }t[mxn]; 24 int nowD,rot=0; 25 inline int cmp(const node a,const node b){ 26 return a.d[nowD]<b.d[nowD]; 27 } 28 LL ans=0; 29 int qx1,qy1,qx2,qy2; 30 void pushup(int rt,int x){ 31 t[rt].mn[0]=min(t[rt].mn[0],t[x].mn[0]); 32 t[rt].mn[1]=min(t[rt].mn[1],t[x].mn[1]); 33 t[rt].mx[0]=max(t[rt].mx[0],t[x].mx[0]); 34 t[rt].mx[1]=max(t[rt].mx[1],t[x].mx[1]); 35 return; 36 } 37 bool in(int rt){ 38 return qx1<=t[rt].mn[0] && t[rt].mx[0]<=qx2 39 && qy1<=t[rt].mn[1] && t[rt].mx[1]<=qy2; 40 } 41 bool out(int rt){ 42 return qx2<t[rt].mn[0] || qy2<t[rt].mn[1] 43 || qx1>t[rt].mx[0] || qy1>t[rt].mx[1]; 44 } 45 int Build(int l,int r,int D){ 46 if(l>r)return 0; 47 int mid=(l+r)>>1; 48 nowD=D; 49 nth_element(t+l,t+mid,t+r+1,cmp); 50 t[mid].l=Build(l,mid-1,D^1); 51 if(t[mid].l){ 52 pushup(mid,t[mid].l); 53 } 54 t[mid].r=Build(mid+1,r,D^1); 55 if(t[mid].r){ 56 pushup(mid,t[mid].r); 57 } 58 t[mid].smm=t[mid].v+t[t[mid].l].smm+t[t[mid].r].smm; 59 /* printf("#%d: l:%d r:%d v:%lld smm:%lld\n", 60 mid,t[mid].l,t[mid].r,t[mid].v,t[mid].smm);*/ 61 return mid; 62 } 63 void query(int rt){ 64 if(!rt)return; 65 if(out(rt)){ 66 return; 67 } 68 if(in(rt)){ 69 ans+=t[rt].smm; 70 return; 71 } 72 if(qx1<=t[rt].d[0] && t[rt].d[0]<=qx2 && 73 qy1<=t[rt].d[1] && t[rt].d[1]<=qy2) 74 ans+=t[rt].v; 75 // printf("fin\n"); 76 if(t[rt].l)query(t[rt].l); 77 if(t[rt].r)query(t[rt].r); 78 return; 79 } 80 int main(){ 81 // freopen("task.in","r",stdin); 82 // freopen("task.out","w",stdout); 83 int i,j,x,y,w; 84 n=read();m=read(); 85 t[0].mn[0]=INF;t[0].mx[0]=-INF; 86 t[0].mn[1]=INF;t[0].mx[1]=-INF; 87 t[0].smm=t[0].v=0; 88 for(i=1;i<=n;i++){ 89 x=read();y=read();w=read(); 90 t[i].d[0]=x; t[i].d[1]=y; t[i].v=w; 91 t[i].mn[0]=t[i].mx[0]=x; 92 t[i].mn[1]=t[i].mx[1]=y; 93 } 94 rot=Build(1,n,0); 95 while(m--){ 96 qx1=read();qy1=read(); 97 qx2=read();qy2=read(); 98 ans=0; 99 query(rot); 100 printf("%lld\n",ans); 101 } 102 return 0; 103 }
转载于:https://www.cnblogs.com/SilverNebula/p/6701473.html
Bzoj4822 [Cqoi2017]老C的任务相关推荐
- [bzoj4823][洛谷P3756][Cqoi2017]老C的方块
Description 老 C 是个程序员. 作为一个懒惰的程序员,老 C 经常在电脑上玩方块游戏消磨时间.游戏被限定在一个由小方格排成的R行C列网格上 ,如果两个小方格有公共的边,就称它们是相邻的, ...
- 洛谷P3755 [CQOI2017]老C的任务 题解
题目传送门 题目描述 老C是个程序员. 最近老C从老板那里接到了一个任务--给城市中的手机基站写个管理系统.作为经验丰富的程序员,老C轻松地完成了系统的大部分功能,并把其中一个功能交给你来实现. 由于 ...
- BZOJ 4823 Luogu P3756 [CQOI2017]老C的方块 (网络流、最小割)
题目链接 (Luogu) https://www.luogu.org/problem/P3756 (BZOJ) http://lydsy.com/JudgeOnline/problem.php?id= ...
- [CQOI2017] 老C的任务(差分 + 树状数组 / K-D tree)
problem luogu-P3755 solution 这题第一眼矩阵内的点权值和,马上就是 K-D tree\text{K-D tree}K-D tree 不过脑子的敲. 这其实就是个二维数点问题 ...
- [CQOI2017] 老C的键盘(树形dp + 组合数)
problem luogu-P3757 solution observation:\text{observation}:observation: hi/2−hih_{i/2}-h_ihi/2−hi ...
- 题解 [CQOI2017] 老 C 的方块
这题我们教练出的. Sto nodgd Orz 一般来说,看到网格题,想到网络流.看到要炸点,考虑染色,这道题的四个形状都是四个格子,考虑染成四色(图片来自 shadowice1984 的题解): 那 ...
- P3755 [CQOI2017]老C的任务
传送门 可以离线,把询问拆成四个,然后把所有的按\(x\)坐标排序,这样就只要考虑\(y\)坐标了.然后把\(y\)坐标离散化,用树状数组统计即可 记得开longlong //minamoto #in ...
- luogu3755 [CQOI2017]老C的任务
扫描线水题. #include <algorithm> #include <iostream> #include <cstdio> using namespace ...
- 4824: [Cqoi2017]老C的键盘3167: [Heoi2013]Sao
题意: 对一棵树的边定向,求拓扑序方案数. 题解: 因为两颗子树相对独立,所以可以树形dp. f [ x ] [ i ] f[x][i] f[x][i]表示x这棵子树,根节点在序列第i位,转移什么就随 ...
最新文章
- 【Linux系统编程】可重入和不可重入函数
- ubuntu14.04安装git
- 纠正存储 dict 的元素前是计算 key 的 hash 值?
- 玩转ptrace (一)
- 嵌入式软件设计第10次实验报告
- 方舟手游服务器设置文件翻译,方舟手游咋设置翻译
- 惠普暗影精灵2更新bios系统,防止电池鼓包
- MongoDB学习笔记之索引(一)
- 数据库建模多表一对多和多对一、一对一、多对多
- Research| 细菌产生的脲酶引起克罗恩病患者的肠道菌群失调
- 家用计算机的计算速度,计算机CPU运算速度是多少
- 十七、HBase更新数据
- H5微信分享 自定义图标和内容(以及二次分享图片丢失的解决办法)
- 文本过滤器Filters
- mRNA数据分析专题
- matlab边角网间接平差计算,12.2测边网与边角网间接平差
- 【数据结构】第十三站:排序(下)归并排序
- MATLAB基本使用方法
- APC型光纤活动连接器有何特点?适合使用在什么场景?
- 线稿上色V3(比V2差别在于这个参考图的处理方式),并且更好用哦
热门文章
- html设置粗体字,如何在HTML输出中设置粗体字段
- android缓存的后台进程,Android应用程序进程生命周期详解
- linux ipc 漏洞,1月19日Linux发现内核0Day漏洞,编号”CVE-2016-0728“
- Bootstrap 3: 使用注意box-sizing细节及解决方法
- 概念性jQuery内容编辑器
- PHP下载CSS文件中的图片
- UIPageControl 分页控件-IOS开发
- GBDT与XGBOOST
- rsync常用参数组合
- 机器学习速成课程 | 练习 | Google Development——编程练习:特征组合