【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. langularJs的MVC模式

    1.数据的挂载 在函数中设置数据 function Aaa($scope){ $scope.name = 'hello'; $scope.age = '20'; } 2.ng-controller 这 ...

  2. 【[TJOI2017]异或和】

    这道题挺神仙的,毕竟这个异或是需要进位的 看到区间和我们很自然的就想到了前缀和 于是处理一下前缀和答案就变成了这个样子 \[⊕\sum_{i=1}^n\sum_{j=1}^{i}pre_i-pre_{ ...

  3. Django中模型(三)

    Django中模型(三) 四.模型成员 1.类属性 objects:是Manager类的一个对象,作用是与数据库进行交互. 定义模型类时,没有定义管理器,则默认创建名为objects的管理器. 2.自 ...

  4. 2018.09.15模拟总结(T1,T3)

    过了一周,终于迎来了第二次模拟(这不是期待的语气),看第一周毒瘤程度,我就觉得接下来的模拟只能更毒瘤. 花了10多分钟读完了三道题,觉得暴力还是挺好写的,然后在每一道题都思索那么几分钟后,觉得还是写暴 ...

  5. 7、Dubbo-配置(2)

    重试次数 通常配合timeout超时设置进行配置 <dubbo:reference "> </dubbo:reference> <dubbo:service i ...

  6. UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-22: ordinal not in range(128)

    在python2.7下,将字符串写入到文件时会出现"UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in p ...

  7. concatenate函数

    numpy.concatenate((a1, a2, ...), axis=0) Join a sequence of arrays along an existing axis.(按轴axis连接a ...

  8. 机器学习基石笔记:Homework #2 decision stump相关习题

    原文地址:http://www.jianshu.com/p/4bc01760ac20 问题描述 程序实现 17-18 # coding: utf-8 import numpy as np import ...

  9. 前端css小米导航栏设置及盒子定位居中问题

    1.小米最上部导航栏设置 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  10. MySQL-5.5.32 配置文件优化详解

    目录 MySQL-5.5.32 配置文件优化详解 一.配置文件说明 2.my-medium.cnf 3.my-large.cnf 4.my-huge.cnf 5.my-innodb-heavy-4G. ...