题意:中文题。

析:按x排序,然后用树状数组维护 y 即可。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-3;
const int maxn = 500000 + 10;
const int maxm = 1e7 + 10;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Query{
int id, x, y, ty, w;
Query() { }
Query(int i, int xx, int yy, int t, int ww) :
id(i), x(xx), y(yy), ty(t), w(ww) { }
bool operator < (const Query &q) const{
return x < q.x || x == q.x && ty < q.ty;
}
};
Query q[maxn*5], tmp[maxn*5]; int ans[maxn];
int sum[maxm]; inline int lowbit(int x){ return -x&x; } void add(int x, int c){
while(x < maxm){
sum[x] += c;
x += lowbit(x);
}
} int query(int x){
int ans = 0;
while(x){
ans += sum[x];
x -= lowbit(x);
}
return ans;
} void dfs(int l, int r){
if(l == r) return ;
int m = l + r >> 1;
dfs(l, m); dfs(m+1, r);
int i = l, j = m+1, k = l;
while(i <= m && j <= r){
if(q[i] < q[j]){
tmp[k++] = q[i];
if(!q[i].ty) add(q[i].y, 1);
++i;
}
else{
tmp[k++] = q[j];
if(q[j].ty) ans[q[j].id] += query(q[j].y) * q[j].w;
++j;
}
}
while(i <= m){
tmp[k++] = q[i];
if(!q[i].ty) add(q[i].y, 1);
++i;
}
while(j <= r){
tmp[k++] = q[j];
if(q[j].ty) ans[q[j].id] += query(q[j].y) * q[j].w;
++j;
}
for(int i = l; i <= r; ++i){
if(!q[i].ty && i <= m) add(q[i].y, -1);
q[i] = tmp[i];
}
} int main(){
scanf("%d %d", &n, &m);
int cnt = 0;
for(int i = 0; i < n; ++i){
int x, y; scanf("%d %d", &x, &y);
q[cnt++] = Query(-1, x+1, y+1, 0, 0);
}
for(int i = 0; i < m; ++i){
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
q[cnt++] = Query(i, x1, y1, 1, 1);
q[cnt++] = Query(i, x2+1, y2+1, 1, 1); q[cnt++] = Query(i, x1, y2+1, 1, -1);
q[cnt++] = Query(i, x2+1, y1, 1, -1);
}
dfs(0, cnt-1);
for(int i = 0; i < m; ++i) printf("%d\n", ans[i]);
return 0;
}

  

BZOJ 1935 Tree 园丁的烦恼 (树状数组)的更多相关文章

  1. [bzoj1935][shoi2007]Tree 园丁的烦恼(树状数组+离线)

    1935: [Shoi2007]Tree 园丁的烦恼 Time Limit: 15 Sec  Memory Limit: 357 MBSubmit: 980  Solved: 450[Submit][ ...

  2. BZOJ1935: [Shoi2007]Tree 园丁的烦恼(树状数组 二维数点)

    题意 题目链接 Sol 二维数点板子题 首先把询问拆成四个矩形 然后离散化+树状数组统计就可以了 // luogu-judger-enable-o2 #include<bits/stdc++.h ...

  3. 【bzoj4822/bzoj1935】[Cqoi2017]老C的任务/[Shoi2007]Tree 园丁的烦恼 树状数组

    原文地址:http://www.cnblogs.com/GXZlegend/p/6825530.html bzoj4822 题目描述 老 C 是个程序员.     最近老 C 从老板那里接到了一个任务 ...

  4. BZOJ 1935: [Shoi2007]Tree 园丁的烦恼 [树状数组 离线 离散化]

    传送门 刚才我还在郁闷网上怎么没人用$CDQ$分治做 突然发现根本没有时间序.... #include<iostream> #include<cstdio> #include& ...

  5. BZOJ 1935 Tree 园丁的烦恼 CDQ分治/主席树

    CDQ分治版本 我们把询问拆成四个前缀和,也就是二维前缀和的表达式, 我们把所有操作放入一个序列中 操作1代表在x,y出现一个树 操作2代表加上在x,y内部树的个数 操作3代表减去在x,y内部树的个数 ...

  6. bzoj 1935 Tree 园丁的烦恼

    题目大意: 一些点,每次查询一个矩形内有多少个点 思路: 因为空间太大 所以不能用什么二维树状数组 需要把这些点和所有查询的矩阵的左下和右上离线下来 先离散化 然后每个子矩阵像二维前缀和那样查询 按照 ...

  7. BZOJ 1878 SDOI 2009 HH项链 树状数组 + 脱机处理

    标题效果:一些珠子项链.珠具有不同的颜色.我们问了很多次有多少种不同的颜色有过一段范围. 思考:这个问题让我学会聪明的离线实践.按左端点排序问题.加工出来的位置每种颜色首次出现.每一种颜色的下一次出现 ...

  8. bzoj 4765 普通计算姬(树状数组 + 分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=4765 很nice的一道题啊(可能是因为卡了n久终于做出来了 题意就是给你一棵带点权的有根树,sum( ...

  9. BZOJ.4888.[TJOI2017]异或和(树状数组)

    BZOJ 洛谷 \(Description\) 求所有区间和的异或和. \(n\leq 10^5,\ \sum a_i\leq 10^6\). \(Solution\) 这样的题还是要先考虑按位做. ...

随机推荐

  1. Eclipse launch configuration----Eclipse运行外部工具

    虽然我们已经有了像 Eclipse 这样高级的 IDE,但是我们有时候也是需要在开发的时候使用 Windows 的命令行,来运行一些独立的程序.在两个程序中切换来切换去是很麻烦的.所以 Eclipse ...

  2. iphone splash screen

    https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articl ...

  3. Technology, globalisation and the squeeze on good jobs

    Technology, globalisation and the squeeze on good jobs技术与全球化冲击好工作“Highest stock market EVER! Jobs ar ...

  4. python判断unicode是否是汉字,数字,英文,或者其他字符

    下面这个小工具包含了 判断unicode是否是汉字,数字,英文,或者其他字符. 全角符号转半角符号. unicode字符串归一化等工作. 还有一个能处理多音字的汉字转拼音的程序,还在整理中. #!/u ...

  5. 吴裕雄 实战PYTHON编程(7)

    import os from win32com import client word = client.gencache.EnsureDispatch('Word.Application')word. ...

  6. sparkSQL、dataframe

    http://www.aboutyun.com/forum.php?mod=viewthread&tid=12358&page=1 空值填充:http://spark.apache.o ...

  7. MapReduce超时原因(Time out after 300 secs)

    目前碰到过三种原因导致 Time out after 300 secs. 1. 死循环 这是最常见的原因.显式的死循环很容易定位,隐式的死循环就比较麻烦了,比如正则表达式.曾经用一个网上抄来的邮箱正则 ...

  8. Week4-作业1:阅读笔记与思考

    我在这三天时间里阅读了<构建之法>的第四章和第十七章,产生了一些疑问和深层次的思考. 第四章 问题1: 书中第68页提到“注释(包括所有源代码)应该只用ASCII字符,不要用中文或其他特殊 ...

  9. intellij idea 的常见配置

    1.视图配置 配置好后如下图:   2.修改字体大小 3.编码修改 4.行号显示 5.控制台字体大小调整 File->Settings->Editor->Colors & F ...

  10. Maven(一)——Maven入门

    一.Maven的基本概念 Maven(翻译为"专家","内行")是跨平台的项目管理工具.主要服务于基于Java平台的项目构建,依赖管理和项目信息管理. 1.1. ...