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的子节点 那么 ...
随机推荐
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- 第二次 作业——APP案例分析
APP案例分析 产品 网易云课堂 选择理由 网易云课堂是从大一就开始使用的一款学习软件,有海量的学习资源,很适合学生课余时间的自主学习 调研,评测 上手体验 第一次打开网易云课堂app的时候,进入的是 ...
- Gradle入门(3):构建第一个Java项目
Gradle插件通过引入特定领域的约定和任务来构建你的项目.Java插件是Gradle自身装载的一个插件.Java插件提供的基本功能远比源代码编译和打包多.它为你的项目建立了一个标准的项目布局,并确保 ...
- vue router 几种方式对比 (转载)
<div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 router-link 组件来导 ...
- HDU 2107 Founding of HDU
http://acm.hdu.edu.cn/showproblem.php?pid=2107 Problem Description 经过慎重的考虑,XHD,8600, LL,Linle以及RPG等A ...
- phantomjsDriver的初始化
public static void main(String[] args) { File file=new File("src/main/resources/drivers"); ...
- oracle 简单的sysTimeStamp类型转date 类型
oracle 简单的SYSTIMESTAMP 类型转date 类型 SELECT SYSTIMESTAMP , SYSTIMESTAMP+0 FROM dual; SAMPLE_TIME ----- ...
- mysql 随机获取一条或多条数据
若要在i ≤r≤ j 这个范围得到一个随机整数r ,需要用到表达式 FLOOR( RAND() * (j – i)+i),RLOOR()取整树部分,RAND()生成0~1的随机数.ROUND(x,n) ...
- 绿色计算大赛决赛 第二阶段 消息传递(斯坦纳树 状压dp+spfa)
传送门 Description 作为公司老板的你手下有N个员工,其中有M个特殊员工.现在,你有一个消息需要传递给你的特殊员工.因为你的公司业务非常紧张,所以你和员工之间以及员工之间传递消息会造成损失. ...
- service依赖dao的接口进行数据传输
service依赖dao的接口进行数据传输