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 ;
}

最新文章

  1. JS几种排序算法
  2. 从零自学Hadoop(16):Hive数据导入导出,集群数据迁移上
  3. T-SQL 基础学习 03
  4. 《DSP using MATLAB》示例Example5.9
  5. BZOJ4209 : 西瓜王
  6. JAVA中implements的用法
  7. 第四周 技术随笔psp
  8. 最长回文子串(Longest Palindromic Substring)-DP问题
  9. Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】
  10. c++ string 对象操作
  11. 单元测试框架 unittest 的运行方法if __name__ == &#39;__main__&#39;: unittest.main()
  12. shell基本命令学习
  13. 赛码网算法: 军训队列( python实现 )
  14. windows server 2008 R2 禁用ipv6和隧道适配器
  15. Java结合SpringBoot拦截器实现简单的登录认证模块
  16. Vasya and Binary String(来自codeforces
  17. select+异步
  18. python ssh之paramiko模块使用
  19. Forward团队-爬虫豆瓣top250项目-项目进度
  20. android的五个进程优先级,内存不足时被清理的顺序

热门文章

  1. 如何使用代码获得一个function module的Where Used List
  2. python入门6 字符串拼接、格式化输出
  3. C语言 Include指令(引用头文件)
  4. POJ-1759 Garland---二分+数学
  5. 2018.12.20 Spring环境如何搭建
  6. 【题解】洛谷P3627 [APIO2009]抢掠计划(缩点+SPFA)
  7. vim_preview_window
  8. js面向对象编程——创建对象
  9. oracle快速添加用户及授权
  10. onload函数不执行