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的子节点 那么 ...
随机推荐
- IO异常 的处理
package com.throwsss; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFou ...
- 【转】python 三种遍历list的方法
[转]python 三种遍历list的方法 #!/usr/bin/env python # -*- coding: utf-8 -*- if __name__ == '__main__': list ...
- python下的Box2d物理引擎的配置
/******************************* I come back! 由于已经大四了,正在找工作 导致了至今以来第二长的时间内没有更新博客.向大家表示道歉 *********** ...
- Struts hibernate Spring 框架原理
转自:http://www.cnblogs.com/javaNewegg/archive/2011/08/28/2156521.html 原理:1.通过Configuration().configur ...
- .NET Socket 简单入门
说到Socket,想必大家都或多或少有所涉及,从最初的计算机网络课程,讲述了tcp协议,而Socket就是对协议的进一步封装,使我们开发人员能够更加容易轻松的进行软件之间的通信. 这个星期刚好接受一个 ...
- Java容器深入浅出之PriorityQueue、ArrayDeque和LinkedList
Queue用于模拟一种FIFO(first in first out)的队列结构.一般来说,典型的队列结构不允许随机访问队列中的元素.队列包含的方法为: 1. 入队 void add(Object o ...
- JVM内存模型一
JVM定义了若干个程序执行期间使用的数据区域.这个区域里的一些数据在JVM启动的时候创建,在JVM退出的时候销毁.而其他的数据依赖于每一个线程,在线程创建时创建,在线程退出时销毁. 程序计数器 程序计 ...
- static变量 方法 类 和final
static变量:声明为static的变量实质上就是全局变量.当声明一个对象时,并不产生static变量的拷贝,而是该类所有的实例变量共用同一个static变量.静态变量与静态方法类似.所有此类实例共 ...
- c++11 委托构造
c++11 委托构造 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #includ ...
- BZOJ 4421: [Cerc2015] Digit Division
4421: [Cerc2015] Digit Division Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 348 Solved: 202[Subm ...