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. Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp+搜索

    题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per ...

  2. Sprint--5.21

    看到作业要求组长就召开小组成员开了一个简短的会议,会议内容大致是这样的: 1.再次明确任务:就是每一个人都要清楚知道自己扮演的角色应该做些什么,怎么去做: 2.组长定时更新博客,每一位小组成员也要写进 ...

  3. DPDK L3fwd 源码阅读

    代码部分 整个L3fwd有三千多行代码,但总体思想就是在L2fwd的基础上,增加网络层的根据 IP 地址进行路由查找的内容. main.c 文件 int main(int argc, char **a ...

  4. SQL之联合查询学习笔记

    定义: 联合查询可合并多个相似的选择查询的结果集.等同于将一个表追加到另一个表,从而实现将两个表的查询组合到一起,使用谓词为UNION或UNION ALL. 语法格式 UNION 可以将两个或两个以上 ...

  5. 【SQLSERVER】动态游标的实现

    方法1: CREATE   TABLE   #tabTmp(id   int)    INSERT   #tabTmp   EXECUTE('SELECT   id   FROM   '+@Table ...

  6. Navicat for MySQL和Navicat Premium之间的区别

    首先两款软件都可以用来管理数据库链接MySQL和MariaDB 相对于新手或者前端工程师使用Navicat for MySQL就够了,功能相对于Navicat Premium比较少Navicat fo ...

  7. CSS3 Selectors All In One

    CSS3 Selectors All In One https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors https://www ...

  8. Tomcat 启动流程

  9. 《编写高质量代码改善JavaScript程序的188个建议》读书笔记

    逗号运算符比较怪异.如    var a =(1,2,3,4);alert(a);// 4      var a = 1,2,3,4;//报错 注意a++和++a的差别,变量在参与运算中不断地变化.v ...

  10. MyFlash闪回恢复数据

    使用限制: .binlog格式必须为row,且binlog_row_image=full. .仅支持5.6与5.. .只能回滚DML(增.删.改). .mysqlbinlog版本请保持一致. 1.安装 ...