【LG4148】简单题

题面

洛谷

题解

\(kdt\)模板题呀。。。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
void chkmin(int &x, int y) { if (x > y) x = y; }
void chkmax(int &x, int y) { if (x < y) x = y; }
const int MAX_N = 4e5 + 5;
const double alpha = 0.75;
const int INF = 1e9;
struct Point { int x[2], w; } p[MAX_N];
struct Node {
int mn[2], mx[2];
int ls, rs, sum, size;
Point tp;
} t[MAX_N];
int ans, N, M, WD, cur, top, rt, rub[MAX_N];
inline bool operator < (const Point &l, const Point &r) { return l.x[WD] < r.x[WD]; }
inline int newnode() {
if (top) return rub[top--];
else return ++cur;
}
void pushup(int o) {
int ls = t[o].ls, rs = t[o].rs;
for (int i = 0; i <= 1; i++) {
t[o].mn[i] = t[o].mx[i] = t[o].tp.x[i];
if (ls) chkmin(t[o].mn[i], t[ls].mn[i]), chkmax(t[o].mx[i], t[ls].mx[i]);
if (rs) chkmin(t[o].mn[i], t[rs].mn[i]), chkmax(t[o].mx[i], t[rs].mx[i]);
}
t[o].sum = t[ls].sum + t[rs].sum + t[o].tp.w, t[o].size = t[ls].size + t[rs].size + 1;
}
int build(int l, int r, int wd) {
if (l > r) return 0;
int mid = (l + r) >> 1, o = newnode();
WD = wd, nth_element(&p[l], &p[mid], &p[r + 1]), t[o].tp = p[mid];
t[o].ls = build(l, mid - 1, wd ^ 1), t[o].rs = build(mid + 1, r, wd ^ 1);
return pushup(o), o;
}
void pia(int o, int num) {
if (t[o].ls) pia(t[o].ls, num);
p[num + t[t[o].ls].size + 1] = t[o].tp, rub[++top] = o;
if (t[o].rs) pia(t[o].rs, num + t[t[o].ls].size + 1);
}
void check(int &o, int wd) {
if (alpha * t[o].size < t[t[o].ls].size || alpha * t[o].size < t[t[o].rs].size)
pia(o, 0), o = build(1, t[o].size, wd);
}
void insert(int &o, int wd, Point tmp) {
if (!o) return (void)(o = newnode(), t[o].ls = t[o].rs = 0, t[o].tp = tmp, pushup(o));
if (tmp.x[wd] <= t[o].tp.x[wd]) insert(t[o].ls, wd ^ 1, tmp);
else insert(t[o].rs, wd ^ 1, tmp);
pushup(o), check(o, wd);
}
bool inner(int x1, int y1, int x2, int y2, int X1, int Y1, int X2, int Y2) { return (X1 >= x1 && X2 <= x2 && Y1 >= y1 && Y2 <= y2); }
int outter(int x1, int y1, int x2, int y2, int X1, int Y1, int X2, int Y2) { return (x1 > X2 || x2 < X1 || y1 > Y2 || y2 < Y1); }
int query(int o, int x1, int y1, int x2, int y2) {
if (!o) return 0;
int res = 0;
if (inner(x1, y1, x2, y2, t[o].mn[0], t[o].mn[1], t[o].mx[0], t[o].mx[1])) return t[o].sum;
if (outter(x1, y1, x2, y2, t[o].mn[0], t[o].mn[1], t[o].mx[0], t[o].mx[1])) return 0;
if (inner(x1, y1, x2, y2, t[o].tp.x[0], t[o].tp.x[1], t[o].tp.x[0], t[o].tp.x[1])) res += t[o].tp.w;
res += query(t[o].ls, x1, y1, x2, y2) + query(t[o].rs, x1, y1, x2, y2);
return res;
}
int main () {
N = gi();
for ( ; ; ) {
int op = gi(); if (op == 3) break;
if (op == 1) insert(rt, 0, (Point){gi()^ ans, gi() ^ ans, gi() ^ ans});
else {
int x1 = gi() ^ ans, y1 = gi() ^ ans, x2 = gi() ^ ans, y2 = gi() ^ ans;
printf("%d\n", ans = query(rt, x1, y1, x2, y2));
}
}
return 0;
}

【LG4148】简单题的更多相关文章

  1. BZOJ 2683: 简单题

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] ...

  2. 【BZOJ-1176&2683】Mokia&简单题 CDQ分治

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

  3. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

  4. Bzoj2683 简单题

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1071  Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...

  5. 这样leetcode简单题都更完了

    这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...

  6. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

  7. HDU 1753 大明A+B(字符串模拟,简单题)

    简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...

  8. 团体程序设计天梯赛-练习集L1-014. 简单题

    L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...

  9. bzoj 4066: 简单题 kd-tree

    4066: 简单题 Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 234  Solved: 82[Submit][Status][Discuss] De ...

随机推荐

  1. Phonegap 目录结构介绍

    1.Src 该目录包含了所有用户要创建的 Java 源文件 2.gen 为开发工具自动创建 3.assets 目录 用于方一些资源文件 css js html 4.res 目录该目录包含了所有的资源文 ...

  2. Guava包学习--EventBus

    之前没用过这个EventBus,然后看了一下EventBus的源码也没看明白,(-__-)b.反正大概就是弄一个优雅的方式实现了观察者模式吧.慢慢深入学习一下. 观察者模式其实就是生产者消费者的一个变 ...

  3. POJ2074 Line of Sight

    嘟嘟嘟 题意:用一条水平线段表示以栋房子:\((x_0, y_0)(x_0', y_0)\).然后有一条低于房子的水平线段\(l_0\),代表你可以到的位置.接下来输入一个数\(n\),一下\(n\) ...

  4. Mysql 创建普通用户、数据库、表、插入记录,用户赋权

    C:\phpStudy\MySQL\bin>mysql -uroot -proot -h127.0.0.1 //创建用户 mysql> insert into mysql.user (ho ...

  5. 关于日期的一些常用方法的封装——dates.js

    针对自己在日常用到的一些日期方法,整理成一个js日期插件,插件定义了一个dates全局对象,继承了Date函数,相当于在Date函数上做了一些扩展. 这个插件会不断更新,所有我之后用到的关于日期的自定 ...

  6. 利用maven开发springMVC项目——开发环境搭建(版本错误解决)

    申明:部分内容参见别人的博客,没有任何的商业用途,只是作为自己学习使用.(大佬博客) 一.相关环境 - eclipse :eclipse-jee-oxygen-3-win32-x86_64(下载地址) ...

  7. PAT——1031. 查验身份证

    一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8, ...

  8. Loadrunner之HTTP脚本编写

    Loadrunner之HTTP脚本编写 刚学习性能测试的时候还是建议以录制脚本为好,从录制的脚本中去了解脚本结构,各个函数的用法,慢慢再去尝试自己去编写脚本,如果想往技术方向发展,建议最好学习一门编程 ...

  9. vlc源码分析(四) 调用libts接收TS流

    代码分析前,先要了解TS流基本概念:TS流之基本概念. VLC解析TS流是通过libts库来分离的,libts库使用libdvbpsi库来解TS表.VLC使用模块加载机制来加载libts库,具体调用的 ...

  10. java中的作用域

    在说明这四个关键字之前,我想就class之间的关系做一个简单的定义,对于继承自己的class,base class可以认为他们都是自己的子女,而对于和自己一个目录下的classes,认为都是自己的朋友 ...