一样是cdq的板子

照着园丁的烦恼就好了

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int w,cntq,cnta,nothing,type,qid,aid;
namespace BIT{
int bit[2000100];
int lowbit(int x){
return x&(-x);
}
void add(int pos,int x){
while(pos<=w){
bit[pos]+=x;
pos+=lowbit(pos);
}
}
int query(int pos){
int ans=0;
while(pos){
ans+=bit[pos];
pos-=lowbit(pos);
}
return ans;
}
void clear(int pos){
while(pos<=w){
if(bit[pos])
bit[pos]=0;
else
break;
pos+=lowbit(pos);
}
}
}; int ans[10100];
struct Query{
int type,val,posx,posy,IorD,aid;
bool operator < (const Query &b) const{
return posx==b.posx?type<b.type:posx<b.posx;
}
}query[200100];
Query tmp[200100];
void cdq(int L,int R){
// printf("%d %d",L,R);
if(R<=L+1)
return;
int mid=(L+R)>>1;
cdq(L,mid);
cdq(mid,R);
int l=L,r=mid,tot=0;
while(l<mid&&r<R){
if(query[l]<query[r]){
if(query[l].type==1)
BIT::add(query[l].posy,query[l].val);
tmp[++tot]=query[l++];
}
else{
if(query[r].type==2)
ans[query[r].aid]+=query[r].IorD*BIT::query(query[r].posy);
tmp[++tot]=query[r++];
}
}
while(l<mid)
tmp[++tot]=query[l++];
while(r<R){
if(query[r].type==2)
ans[query[r].aid]+=query[r].IorD*BIT::query(query[r].posy);
tmp[++tot]=query[r++];
}
for(int i=1;i<=tot;i++){
BIT::clear(tmp[i].posy);
query[L+i-1]=tmp[i];
}
}
int main(){
scanf("%d %d",&nothing,&w);
scanf("%d",&type);
w++;
while(type!=3){
if(type==1){
int x,y,a;
scanf("%d %d %d",&x,&y,&a);
// x+=2;y+=2;
x++,y++; query[++qid].type=1;
query[qid].posy=y;
query[qid].posx=x;
query[qid].val=a;
}
else{
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
// x1+=2,x2+=2,y1+=2,y2+=2;
x1++,x2++,y1++,y2++; query[++qid].type=2;
query[qid].aid=++aid;
query[qid].IorD=1;
query[qid].posx=x2;
query[qid].posy=y2; query[++qid].type=2;
query[qid].aid=aid;
query[qid].IorD=-1;
query[qid].posx=x1-1;
query[qid].posy=y2; query[++qid].type=2;
query[qid].aid=aid;
query[qid].IorD=-1;
query[qid].posx=x2;
query[qid].posy=y1-1; query[++qid].type=2;
query[qid].aid=aid;
query[qid].IorD=1;
query[qid].posx=x1-1;
query[qid].posy=y1-1;
}
scanf("%d",&type);
}
cdq(0,qid+1);
for(int i=1;i<=aid;i++)
printf("%d\n",ans[i]);
return 0;
}

P4390 [BOI2007]Mokia 摩基亚(cdq分治)的更多相关文章

  1. Luogu P4390 [BOI2007]Mokia 摩基亚 | CDQ分治

    题目链接 $CDQ$分治. 考虑此时在区间$[l,r]$中,要计算$[l,mid]$中的操作对$[mid+1,r]$中的询问的影响. 计算时,排序加上树状数组即可. 然后再递归处理$[l,mid]$和 ...

  2. cogs1752[boi2007]mokia 摩基亚 (cdq分治)

    [题目描述] 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如“用户C的位置在哪?”的问题,精确到毫米.但其真正高科技之处在于,它能 ...

  3. P4390 [BOI2007]Mokia 摩基亚 (CDQ解决三维偏序问题)

    题目描述 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如"用户C的位置在哪?"的问题,精确到毫米.但其真正高科 ...

  4. 洛谷 P4390 [BOI2007]Mokia 摩基亚 解题报告

    P4390 [BOI2007]Mokia 摩基亚 题目描述 摩尔瓦多的移动电话公司摩基亚(\(Mokia\))设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如"用户 ...

  5. [洛谷P4390][BOI2007]Mokia 摩基亚

    题目大意: 维护一个W*W的矩阵,每次操作可以增加某格子的权值,或询问某子矩阵的总权值. 题解:CDQ分治,把询问拆成四个小矩形 卡点:无 C++ Code: #include <cstdio& ...

  6. P4390 [BOI2007]Mokia 摩基亚

    传送门 对于一个询问 $(xa,ya),(xb,yb)$,拆成 $4$ 个询问并容斥一下 具体就是把询问变成求小于等于 $xb,yb$ 的点数,减去小于等于 $xa-1,yb$ 和小于等于 $xb,y ...

  7. 【BZOJ1176】[BOI2007]Mokia 摩基亚

    [BZOJ1176][BOI2007]Mokia 摩基亚 题面 bzoj 洛谷 题解 显然的\(CDQ\)\(/\)树套树题 然而根本不想写树套树,那就用\(CDQ\)吧... 考虑到点\((x1,y ...

  8. [BOI2007]Mokia 摩基亚

    Description: 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如"用户C的位置在哪?"的问题,精确到毫 ...

  9. 【cdq分治】【P4390】[BOI2007]Mokia 摩基亚

    Description 给你一个 \(W~\times~W\) 的矩阵,每个点有权值,每次进行单点修改或者求某子矩阵内权值和,允许离线 Input 第一行是两个数字 \(0\) 和矩阵大小 \(W\) ...

随机推荐

  1. rpgmakermv(10) GraphicalDesignMode

    插件地址:https://github.com/triacontane/RPGMakerMV/blob/master/GraphicalDesignMode.js 原文: メニュー画面や戦闘画面など各 ...

  2. html5-textarea元素

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  3. C. Primes or Palindromes?

    prime numbers non greater than n is about . We can also found the amount of palindrome numbers with ...

  4. win7 64位 python启动报错:无法启动此程序,因为计算机中丢失api-ms-win-crt-process-l1-1-0.dll

    安装python3.7,安装成功后,在cmd窗口输入python检查是否安装成功,报错:无法启动此程序,因为计算机中丢失api-ms-win-crt-process-l1-1-0.dll 在网上查询了 ...

  5. BufferReader BufferWriter

    Copying information from one file to another with 'BufferReader BufferWriter' public class Demo5 { p ...

  6. DataBase(28)

    1.数据库管理系统(DataBase Management System,DBMS):指一种操作和管理数据库的大型软件,用于建立.使用和维护数据库,对数据库进行统一管理和控制,以保证数据库的安全性和完 ...

  7. JVM探秘4---垃圾收集器介绍

    Java虚拟机有很多垃圾收集器 下面先来了解HotSpot虚拟机中的7种垃圾收集器:Serial.ParNew.Parallel Scavenge.Serial Old.Parallel Old.CM ...

  8. 转:WCF传送二进制流数据基本实现步骤详解

    来自:http://developer.51cto.com/art/201002/185444.htm WCF传送二进制流数据基本实现步骤详解 2010-02-26 16:10 佚名 CSDN   W ...

  9. nodejs typescript怎么发送get、post请求,如何获取网易云通信token

    nodejs typescript怎么发送get.post请求,如何获取网易云通信token yarn add jshashesyarn add superagent检查语法yarn lint==== ...

  10. java获取前一天时间SimpleDateFormat,java判断某个时间段

    java获取前一天时间SimpleDateFormat SimpleDateFormat predf = new SimpleDateFormat("yyyy-MM-dd"); D ...