1 #include 2 #include 3 #include 4 typedef __int64 LL; 5 using namespace std; 6 #define MAXN 1010 7 struct Point 8 { 9 int x,y,z; 10 void Input() 11 { 12 scanf("%d%d%d",&x,&y,&z); 13 } 14 }; 15 struct Rectangle 16 { 17 Point a,b; 18 }; 19 struct Seg 20 { 21 int left,right,high,flag; 22 friend bool operator<(Seg a,Seg b) 23 { 24 if(a.high==b.high) 25 return a.flag 2) 41 tree[rt].more=tree[rt].two=tree[rt].one=X[R+1]-X[L]; 42 else if(tree[rt].cover==2) 43 { 44 tree[rt].one=tree[rt].two=X[R+1]-X[L]; 45 if(L==R) 46 tree[rt].more=0; 47 else 48 tree[rt].more=tree[rt<<1].one+tree[rt<<1|1].one; 49 } 50 else if(tree[rt].cover==1) 51 { 52 tree[rt].one=X[R+1]-X[L]; 53 if(L==R) 54 tree[rt].two=tree[rt].more=0; 55 else 56 { 57 tree[rt].two=tree[rt<<1].one+tree[rt<<1|1].one; 58 tree[rt].more=tree[rt<<1].two+tree[rt<<1|1].two; 59 } 60 } 61 else 62 { 63 if(L==R) 64 tree[rt].more=tree[rt].two=tree[rt].one=0; 65 else 66 { 67 tree[rt].more=tree[rt<<1].more+tree[rt<<1|1].more; 68 tree[rt].one=tree[rt<<1].one+tree[rt<<1|1].one; 69 tree[rt].two=tree[rt<<1].two+tree[rt<<1|1].two; 70 } 71 } 72 } 73 void Update(int x,int y,int flag,int L,int R,int rt) 74 { 75 if(x<=L&&R<=y) 76 { 77 tree[rt].cover+=flag; 78 PushUp(L,R,rt); 79 } 80 else 81 { 82 int mid=(L+R)>>1; 83 if(x<=mid) 84 Update(x,y,flag,L,mid,rt<<1); 85 if(y>mid) 86 Update(x,y,flag,mid+1,R,rt<<1|1); 87 PushUp(L,R,rt); 88 } 89 } 90 int main() 91 { 92 LL ans,temp; 93 int t,n,i,j,nx,nz,cnt,x,y,ca=1; 94 scanf("%d",&t); 95 while(t--) 96 { 97 scanf("%d",&n); 98 for(nx=nz=i=0;i