这题的思路还是挺巧妙的
最关键的一步是我们改求与当前矩形不相交的矩形个数
那么显然可以容斥,用完全在上面的+下面的+左面的+右面的-四个角上被重复算的
前面的四个比较好搞,以上面举例,插入矩形时把矩形的下边界插入树状数组,查询时抓住当前矩形的上边界在树状数组里查就好了
四个角的部分,以左上角为例,插入矩形时把矩形的右下角记录下来,查询时查矩形的左上角的左上方有多少个点
所以现在相当于要实现在平面里面加点删点,然后求一个矩形区域内有多少个点
考虑到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=