bzoj千题计划144:bzoj1176: [Balkan2007]Mokia
http://www.lydsy.com/JudgeOnline/problem.php?id=1176
CDQ分治
#include<cstdio>
#include<iostream>
#include<algorithm> #define lowbit(x) x&-x using namespace std; #define N 160001
#define M 10001 typedef long long LL; int w;
LL c[]; struct node
{
int id;
int x,y,bl,mul;
bool ty;
}e[N+M*],tmp[N+M*]; LL ans[M]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} bool cmp(node p,node q)
{
if(p.x!=q.x) return p.x<q.x;
return p.ty<q.ty;
} void change(int x,int k)
{
while(x<=w)
{
c[x]+=k;
x+=lowbit(x);
}
} LL query(int x)
{
LL sum=;
while(x)
{
sum+=c[x];
x-=lowbit(x);
}
return sum;
} void solve(int l,int r)
{
if(l==r) return;
int mid=l+r>>;
int sum=;
for(int i=l;i<=r;++i)
{
if(!e[i].ty && e[i].id<=mid) change(e[i].y,e[i].mul);
else if(e[i].ty && e[i].id>mid) ans[e[i].bl]+=e[i].mul*query(e[i].y);
}
for(int i=l;i<=r;++i)
{
if(!e[i].ty && e[i].id<=mid) change(e[i].y,-e[i].mul);
}
int L=l,R=mid+;
for(int i=l;i<=r;++i)
{
if(e[i].id<=mid) tmp[L++]=e[i];
else tmp[R++]=e[i];
}
for(int i=l;i<=r;++i) e[i]=tmp[i];
solve(l,mid);
solve(mid+,r);
} int main()
{
int s;
read(s); read(w);
int ty,lx,ly,rx,ry,k;
int tot=,cnt=;
while(scanf("%d",&ty))
{
if(ty==)
{
e[++tot].id=tot;
read(e[tot].x);
read(e[tot].y);
read(e[tot].mul);
}
else if(ty==)
{
read(lx); read(ly); read(rx); read(ry);
cnt++;
e[++tot].id=tot; e[tot].bl=cnt; e[tot].mul=; e[tot].ty=true; e[tot].x=rx; e[tot].y=ry;
e[++tot].id=tot; e[tot].bl=cnt; e[tot].mul=; e[tot].ty=true; e[tot].x=lx-; e[tot].y=ly-;
e[++tot].id=tot; e[tot].bl=cnt; e[tot].mul=-; e[tot].ty=true; e[tot].x=lx-; e[tot].y=ry;
e[++tot].id=tot; e[tot].bl=cnt; e[tot].mul=-; e[tot].ty=true; e[tot].x=rx; e[tot].y=ly-; }
else break;
}
sort(e+,e+tot+,cmp);
solve(,tot);
for(int i=;i<=cnt;++i) cout<<ans[i]<<'\n';
}
bzoj千题计划144:bzoj1176: [Balkan2007]Mokia的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- 软工 · 第十二次作业 - Beta答辩总结
福大软工 · 第十二次作业 - Beta答辩总结 写第十二次的时候操作失误直接在Beta版本的博客里改了...第七次冲刺的作业链接补在这里 Beta(7/7) 组长本次博客作业链接 项目宣传视频链接 ...
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- Virtualbox+Ubuntu安装,VERR_VMX_MSR_ALL_VMX_DISABLED解决
学习链接:基于VirtualBox虚拟机安装Ubuntu图文教程--娄老师 启动虚拟机遇到的问题:BIOS中VT-x在所有CPU模式下被禁用(VERR_VMX_MSR_ALL_VMX_DISABLED ...
- OSI协议和TCP/IP协议笔记
1.OSI协议: 第7层应用层:OSI中的最高层.是用户与网络的接口.该层通过应用程序来完成网络用户的应用需求,如文件传输.收发电子邮件等.在此常见的协议有:HTTP,HTTPS,FTP,TELNET ...
- JTS
在这个系列的 第 1 部分,我们讨论了事务并研究了它们的基本属性 ― 原子性(atomicity).一致性(consistency).孤立性(isolation)和持久性(durability).事务 ...
- 二叉查找树ADT--C语言描述
首先给出此ADT的声明: struct TreeNode; typedef struct TreeNode *Position; typedef struct TreeNode *SearchTree ...
- [转帖] SQLNET.ORA的处理.
被一个客户端连接远程数据库阻塞超时的问题困扰了好久,最后终于找到了答案 https://blog.csdn.net/herobox/article/details/16985097 Oracle ...
- facenet模型训练
做下记录,脚本如下: 对比 python3 src/compare.py ../models/-/ ../faces/pyimgs/dashenlin/ytwRkvSdG1000058.png ../ ...
- List,Set和Map详解及其区别和他们分别适用的场景
Java中的集合包括三大类,它们是Set(集).List(列表)和Map(映射),它们都处于java.util包中,Set.List和Map都是接口,它们有各自的实现类.Set的实现类主要有HashS ...
- 在CentOS中安装与配置SVN的方法
安装说明系统环境:CentOS-6.4安装方式:yum install (源码安装容易产生版本兼容的问题)安装软件:系统自动下载SVN软件 1.检查已安装版本 #检查是否安装了低版本的SVN[root ...