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. Computer Hardware

    Computer Hardware Para 1 Computer hardware can be divides into four categories: input hardware, stor ...

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

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

  3. 什么是React中的组件

    组件就是页面上的一部分.如图,左边是一个网页.右边是对应的一个组件图.我们可以把一个大的网页拆分成很多小的部分.比如标题部分,对应一个组件,就是标题组件.搜索部分,对应的组件就是搜索组件.而这个搜索组 ...

  4. Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

    任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...

  5. EntityFrameWork简单操作 EF数据上下文对象操作数据增删改差及批处理

    /// <summary> /// EF针对 留言数据库 的 数据上下文对象!!!! /// </summary> static LeaveWordBoradEntities ...

  6. linux系统命令与常识

    之前短期学过linux,用到时才发现已经忘得一干二净了. 现在对学过的和了解到的做一个总结: 先明确一些使用工具: winscp : WinSCP是一个Windows环境下使用SSH的开源图形化SFT ...

  7. Viewpager实现今日头条顶部导航的功能

    利用简单的Textview 和Viewpager实现滑动.点击换页的效果,效果图如下: 先上布局文件代码: <?xml version="1.0" encoding=&quo ...

  8. C#实现打印

    C#实现导出pdf文件,打印 using System; using System.Collections.Generic; using System.Linq; using System.Web; ...

  9. [USACO1.5]数字三角形 Number Triangles

    题目描述 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 5 ...

  10. Windows获取物理内存的2种方式 - 随笔记录

    typedef enum _SYSTEM_INFORMATION_CLASS { SystemBasicInformation, SystemProcessorInformation, // obso ...