1176: [Balkan2007]Mokia

链接

分析

  三维偏序问题,CDQ分治论文题。

代码

 #include<bits/stdc++.h>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for (;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} int ans[],W;
struct Que{
int ty,x,y,w,id;
bool operator < (const Que &a) const {
return x == a.x ? ty < a.ty : x < a.x;
}
}A[*++],B[*++]; struct Bit{
int sum[];
void update(int p,int v) {
for (; p<=W; p+=p&(-p)) sum[p] += v;
}
int query(int p) {
int ans = ;
for (; p; p-=p&(-p)) ans += sum[p];
return ans;
}
void clear(int p) {
for (; p<=W&&sum[p]; p+=p&(-p)) sum[p] = ;
}
}bit; void CDQ(int L,int R) {
if (L == R) return ;
int M = (L + R) >> ;
CDQ(L,M);
CDQ(M+,R);
int i = L, j = M + ,k = L;
while (i <= M && j <= R) {
if (A[i] < A[j]) {
if (A[i].ty == ) bit.update(A[i].y,A[i].w);
B[k++] = A[i++];
}
else {
if (A[j].ty == ) ans[A[j].id] += A[j].w * bit.query(A[j].y);
B[k++] = A[j++];
}
}
while (i <= M) B[k++] = A[i++];
while (j <= R) {
ans[A[j].id] += A[j].w * bit.query(A[j].y);
B[k++] = A[j++];
}
for (int i=L; i<=R; ++i) {
bit.clear(A[i].y);
A[i] = B[i];
}
}
int main() { W = read();W = read(); // 把W在这里int了一下,然后。。。
int Index = ,QueIndex = ; while () {
int opt = read();
if (opt==) break;
if (opt==) {
int a = read(),b = read(),val = read();
A[++Index] = (Que){,a,b,val,};
}
else {
int a1 = read(),b1 = read(),a2 = read(),b2 = read();
A[++Index] = (Que){,a1-,b1-,,++QueIndex};
A[++Index] = (Que){,a1-,b2,-,QueIndex};
A[++Index] = (Que){,a2,b1-,-,QueIndex};
A[++Index] = (Que){,a2,b2,,QueIndex};
}
}
CDQ(,Index);
for (int i=; i<=QueIndex; ++i) printf("%d\n",ans[i]);
return ;
}

1176: [Balkan2007]Mokia的更多相关文章

  1. BZOJ 1176: [Balkan2007]Mokia

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 2012  Solved: 896[Submit][St ...

  2. BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )

    考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...

  3. BZOJ 1176[Balkan2007]Mokia(CDQ分治)

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 3381  Solved: 1520[Submit][S ...

  4. 【BZOJ】1176: [Balkan2007]Mokia(cdq分治)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1176 在写这题的时候思维非常逗啊........2333................... 最后 ...

  5. BZOJ 1176 [Balkan2007]Mokia ——CDQ分治

    [题目分析] 同BZOJ2683,只需要提前处理s对结果的影响即可. CDQ的思路还是很清晰的. 排序解决一维, 分治时间, 树状数组解决一维. 复杂度是两个log [代码] #include < ...

  6. 1176: [Balkan2007]Mokia - BZOJ

    Description维护一个W*W的矩阵,每次操作可以增加某格子的权值,或询问某子矩阵的总权值. 修改操作数M<=160000,询问数Q<=10000,W<=2000000.Inp ...

  7. BZOJ 1176: [Balkan2007]Mokia [CDQ分治]

    题意: 有一个n * n的棋盘,每个格子内有一个数,初始的时候全部为0.现在要求维护两种操作: 1)Add:将格子(x, y)内的数加上A. 2)Query:询问矩阵(x0, y0, x1, y1)内 ...

  8. bzoj 1176: [Balkan2007]Mokia&&2683: 简单题 -- cdq分治

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MB Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要 ...

  9. 【BZOJ】1176: [Balkan2007]Mokia

    [题意]n*n的矩阵,初始值为0(题面有误),m次操作,增加一个格子的权值,或查询子矩阵和.n<=2*10^6.(m应该较题面所述偏大). [算法]CDQ分治(算法知识见数据结构) [题解]三维 ...

随机推荐

  1. python入门9 条件语句

    条件语句: if 条件为真: 执行语句块 (执行完结束不执行elif,else) elif 条件为真: 执行语句块 (执行完结束不执行else) else: 执行语句块 #coding:utf-8 # ...

  2. 【转载】SSH login without password 免密登陆

    Your aim You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic l ...

  3. google Cayley图谱数据库初试

    一.安装 mkdir cayley cd cayley mkdir src export GOPATH=$(pwd) go get github.com/google/cayley go build ...

  4. 笔记本win8系统共享wifi上网方法

    华硕笔记本电脑,安装了win8系统,使用wifi上网,由于连接无线路由的机器太多,超过路由连接数上限,因此转为使用笔记本共享wifi方式给手机上网. 最终上网方式为: 笔记本网卡接入无线路由器上网,笔 ...

  5. CFS调度分析(内核版本:2.6.34)

    CFS调度分析(内核版本:2.6.34) 1.时间记账 CFS不再有时间片的概念,他维护的是每个进程运行的时间记账 使用调度器实体结构来追踪进程运行记账: <linux/sched.h> ...

  6. POJ 1423 斯特林

    题意:进制问题 分析: 打表,但是要用不能 long long 型,超内存. n! = log_{10}\sqrt{2{\pi}n}*(\frac{n}e)^n 精度要求 #include <c ...

  7. 【[SDOI2009]晨跑】

    板子 题意就是每个点只能经过一次 所以非常显然拆点,除去\(1,n\)每个点\(i\)向\(i'\)连一条容量为\(1\)费用为\(0\)的边 剩下的边按照输入给出的建就好了 代码 #include& ...

  8. 2018.12.21 如何在现有的Eclipse(4.9.0版本)中安装STS (Spring Tool Suite ) Mac环境下

    在Eclipse中安装STS正确步骤实现方式 1.简介说明       spring Tool Suite(sts)就是一个基于Eclipse的开发环境, 用于开发Spring应用程序.它提供了一个现 ...

  9. 【luogu P1144 最短路计数】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1144 #include <iostream> #include <cstdio> # ...

  10. 解密Spring加载的Properties文件

    Spring的框架中,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类可以将.properties(key ...