1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#include<bits/stdc++.h> #define re register typedef long long ll; typedef unsigned long long ull; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...Arc> inline void read(T &x,Arc &...arc){ read(x),read(arc...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+48); } inline void write(char c){ putchar(c); } inline void write(bool x){ putchar(x?'1':'0'); } inline void write(char *s){ while(*s!='\0') putchar(*s++); } inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...Arc> inline void write(T x,Arc ...arc){ write(x),write(arc...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } using Pir=std::pair<int,int>; #define fir first #define sec second #define Mkr std::make_pair const int MAXN=1e6+10; std::set<Pir>Hash; int Case,N,M,Q,Idx,Cnt,Tot,Total; int Val[MAXN]; struct Query { int pos,l,r,val; bool operator<(const Query &x) const { return pos<x.pos; } }Qry[MAXN]; struct Line { int opt,x,l,r; }Bl[MAXN]; struct Cross { int lx,rx,ly,ry; }Cr[6]; #define ls (p<<1) #define rs (p<<1|1) struct Segment { int l,r,val,tag; }Tr[MAXN<<2]; inline void pushUp(int p) { if(Tr[p].tag>0) Tr[p].val=Val[Tr[p].r+1]-Val[Tr[p].l]; else Tr[p].val=Tr[ls].val+Tr[rs].val; } void build(int p,int l,int r) { Tr[p].l=l,Tr[p].r=r,Tr[p].val=Tr[p].tag=0; if(l==r) return ; int mid=(l+r)>>1; build(ls,l,mid),build(rs,mid+1,r); } void modifyAdd(int p,int l,int r,int v) { if(Val[Tr[p].r+1]<=l||r<=Val[Tr[p].l]) return ; if(l<=Val[Tr[p].l]&&Val[Tr[p].r+1]<=r) { Tr[p].tag+=v; return pushUp(p); } modifyAdd(ls,l,r,v),modifyAdd(rs,l,r,v); pushUp(p); } bool Del[6]; int main() { read(Case,N,M,Q); for(int i=1,opt,lx,rx,ly,ry;i<=Q;++i) { read(opt,lx,ly,rx,ry); if(opt<=2) { Qry[++Idx]=(Query){ly,lx,rx+1,1}; Qry[++Idx]=(Query){ry+1,lx,rx+1,-1}; Val[++Total]=lx,Val[++Total]=rx+1; if(opt==1) Bl[++Cnt]=(Line){1,ly,lx,rx}; else Bl[++Cnt]=(Line){2,lx,ly,ry}; } else Cr[++Tot]=(Cross){lx,rx,ly,ry}; } std::sort(Qry+1,Qry+Idx+1); std::sort(Val+1,Val+Total+1); Total=std::unique(Val+1,Val+Total+1)-Val-1; build(1,1,Total-1); ll ans=0; for(int i=1;i<=Idx;++i) { ans+=1ll*Tr[1].val*(Qry[i].pos-Qry[i-1].pos); modifyAdd(1,Qry[i].l,Qry[i].r,Qry[i].val); } for(int i=1;i<=Tot;++i) for(int j=i+1;j<=Tot;++j) { if(Del[i]||Del[j]) continue; auto a=Cr[i],b=Cr[j]; if(a.ly-a.lx==b.ly-b.lx) if(std::max(a.lx,b.lx)<=std::min(a.rx,b.rx)) { checkMin(Cr[i].lx,Cr[j].lx), checkMax(Cr[i].rx,Cr[j].rx), checkMin(Cr[i].ly,Cr[j].ly), checkMax(Cr[i].ry,Cr[j].ry); Del[j]=1; } } for(int i=1;i<=Tot;++i) { if(Del[i]) continue; auto c=Cr[i]; int res=0;Hash.clear(); for(int j=1;j<=Cnt;++j) { auto b=Bl[j]; if(b.opt==1) { if(c.ly<=b.x&&b.x<=c.ry) if(b.l<=(c.lx+b.x-c.ly)&&(c.lx+b.x-c.ly)<=b.r) if(Hash.find(Mkr(c.lx+b.x-c.ly,b.x))==Hash.end()) { Hash.insert(Mkr(c.lx+b.x-c.ly,b.x)); ++res; } } else { if(c.lx<=b.x&&b.x<=c.rx) if(b.l<=(c.ly+b.x-c.lx)&&(c.ly+b.x-c.lx)<=b.r) if(Hash.find(Mkr(b.x,c.ly+b.x-c.lx))==Hash.end()) { Hash.insert(Mkr(b.x,c.ly+b.x-c.lx)); ++res; } } } ans+=c.rx-c.lx+1-res; } write(ans,'\n'); return 0; }
|