【HAOI】贴海报
MZOJ贴海报
.......我真的没带脑子在打
忘了pup
然后数字个数应该为m=unique(c+1,c+cnt+1)-c;
然而我是unique(c+1,c+cnt+1)-c;m=lower_bound(c,c+cnt+1,inf)-c;
..........
数组大小也开小了.....
心好累.........
非要离散化版
#include
using namespace std;
#define ll long long
#define lson (o<<1)
#define rson (o<<1|1)
const int N=1000+5,M=1000000+5,inf=0x3f3f3f3f;
int n,m,a[N],b[N],c[N<<2],cnt,ans;
bool yes,tree[N<<4];
template void rd(t &x){
x=0;int w=0;char ch=0;
while(!isdigit(ch)) w|=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x=w?-x:x;
}
void pup(int o){tree[o]=tree[lson]&&tree[rson];}
void mdf(int o,int l,int r,int x,int y){
if(l > y||r < x) return;
if(tree[o]) return;
if(x < = l&&r < = y){yes=1,tree[o]=1;return;}
int mid=l+r>>1;
mdf(lson,l,mid,x,y),mdf(rson,mid+1,r,x,y);
pup(o);//!!!!!!!!!!!!!!!!!!!!
}
int main(){
freopen("in.txt","r",stdin);
// freopen("numbers.out","w",stdout);
int T;rd(T);
while(T--){
ans=cnt=0;
memset(tree,0,sizeof(tree));
rd(n);
c[++cnt]=inf,c[++cnt]=0;
for(int i=1;i < =n;++i)
rd(a[i]),rd(b[i]),c[++cnt]=a[i],c[++cnt]=a[i]+1,c[++cnt]=b[i],c[++cnt]=b[i]+1;
sort(c+1,c+cnt+1);m=unique(c+1,c+cnt+1)-c;
// m=lower_bound(c,c+cnt+1,inf)-c;
for(int i=n,x,y;i;--i){
x=lower_bound(c+1,c+m+1,a[i])-c;
y=lower_bound(c+1,c+m+1,b[i])-c;
yes=0;
mdf(1,1,m,x,y);
if(yes) ++ans;
}
printf("%d\n",ans);
}
return 0;
}