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的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  3. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  4. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  5. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  6. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  7. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  8. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

  9. bzoj千题计划250:bzoj3670: [Noi2014]动物园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...

随机推荐

  1. TCP/IP Illustrated Vol1 Second Edition即英文版第二版,TCP部分个人勘误

    目前已经有了英文版第二版的TCPIP详解,中文版暂时还没有,但是英文版还是有好几处错误,作者和官方竟然没有维护一个勘误表. 个人阅读过程中针对TCP部分可能有问题的地方简单勘误一下 P596:示意图中 ...

  2. HDU 2106 母猪的故事

    http://acm.hdu.edu.cn/showproblem.php?pid=2160 Problem Description 话说现在猪肉价格这么贵,著名的ACBoy 0068 也开始了养猪生 ...

  3. Powershell笔记之help about_XXX

    <<about_Arrays>> 1. 一直好奇gettype()输出中的Name这一列的Object[]是什么意思,现在终于明白了,请看下面的例子: 2. GM的不同用法 $ ...

  4. [转帖]脑残式网络编程入门(二):我们在读写Socket时,究竟在读写什么?

    脑残式网络编程入门(二):我们在读写Socket时,究竟在读写什么?     http://www.52im.net/thread-1732-1-1.html   1.引言 本文接上篇<脑残式网 ...

  5. JS 日期 自动补齐 “2017-11-22 14:43”

    var myDate = new Date(); var myN = myDate.getFullYear(); var myY = myDate.getMonth(); var myR = myDa ...

  6. (暂时弃坑)ACM数论之旅15---置换群与Polya定理(我把标题看成poi了,poipoipoi(*≧▽≦)ツ)

    (挖坑...) ////////////////////////////////////////////////// 暂时弃坑 开学了,有空再写....

  7. 怎样使用ADO中的UpdateBatch方法(200分)

    诸位: 我在使用ADO组件(ADOQuery.ADODataSet)的BatchUpdate模式时,系统竟不认识UpdateBatch.CancelBatch方法.这是怎么回事?我的运行环境是Win2 ...

  8. False Ordering LightOJ - 1109(暴力。。唉,。又是一个水题。。)

    We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4 ...

  9. git gitignore 如何添加,为何添加了无效

    需求:一个新项目源码要挂载在GIT服务器上,但是里面的obj文件夹,bin文件夹,.exe文件不提交(每次) 有两种情况出现 1.项目初始化的时候就加入拦截规则文件  gitignore 具体步骤请参 ...

  10. [BZOJ1500][NOI2005]维修数列 解题报告 Splay

    Portal Gun:[BZOJ1500][NOI2005]维修数列 有一段时间没写博客了,最近在刚数据结构......各种板子背得简直要起飞,题目也是一大堆做不完,这里就挑一道平衡树的题来写写好了 ...