CodeChef QRECT: Rectangle Query 题解

这题的思路还是挺巧妙的
最关键的一步是我们改求与当前矩形不相交的矩形个数
那么显然可以容斥,用完全在上面的+下面的+左面的+右面的-四个角上被重复算的
前面的四个比较好搞,以上面举例,插入矩形时把矩形的下边界插入树状数组,查询时抓住当前矩形的上边界在树状数组里查就好了
四个角的部分,以左上角为例,插入矩形时把矩形的右下角记录下来,查询时查矩形的左上角的左上方有多少个点
所以现在相当于要实现在平面里面加点删点,然后求一个矩形区域内有多少个点
考虑到cc没有空间限制,刚开始无脑上了动态开点二维线段树,拼命卡常,把线段树换成非递归的又把外层线段树换成树桩才过

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=acos(-1);

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

struct BIT
{
    int c[400048];
    inline void init() {
  memset(c,0,sizeof(c));}
    inline void update(int x,int lim,int delta) {
  while (x<=lim) c[x]+=delta,x+=LOWBIT(x);}
    inline int query(int x) {
  int res=0;while (x) res+=c[x],x-=LOWBIT(x);return res;}
}up,down,lft,rght;

int n,itot1,itot2;
int ind[100048],indtot=0;

struct Query
{
    int type;
    int x1,y1,x2,y2,t;
    int nx1,ny1,nx2,ny2;
}a[100048];

struct point
{
    int val;
    int from;bool type;
    inline bool operator < (const point &x) const {
  return val<x.val;}
}b[500048];int btot;

namespace SegmentTree
{
    int tree[5][(330+5)*200048];
    int lson[(330+5)*200048],rson[(330+5)*200048];int tot=0;
    int lis[100048],litot=0;
    inline void updatey(int cur,int type,int pos,int delta,int l,int r)
    {
        litot=
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值