POJ 2528(数据有误的线段树)
来源:互联网 发布:如何看淘宝信誉 编辑:程序博客网 时间:2024/04/26 18:21
此题数据有误……
是我英文太差,还是答案出错……
Program P2528;const maxn=10000; maxr=10000000;var t,n,i,j,k:longint; a,b,v:array[1..maxn*2] of longint; h:array[1..maxr] of longint; col:array[1..maxn*100] of longint; visit:array[1..maxn*2] of boolean;procedure qsort(l,r:longint);var i,j,m,p:longint;begin i:=l; j:=r; m:=v[(l+r) div 2]; repeat while v[i]<m do inc(i); while v[j]>m do dec(j); if i<=j then begin p:=v[i]; v[i]:=v[j]; v[j]:=p; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r);end;procedure update(l,r,sonl,sonr,root,color:longint);var i,j,k,mid:longint;begin mid:=(l+r) shr 1; if (sonl<=l) and (r<=sonr) then begin col[root]:=color; exit; end; if (col[root]>=0) then begin col[root*2]:=col[root]; col[root*2+1]:=col[root]; col[root]:=-1; end; if not((mid<sonl) or (sonr<l)) then update(l,mid,sonl,sonr,root*2,color); if not((r<sonl) or (sonr<mid+1)) then update(mid+1,r,sonl,sonr,root*2+1,color);end;function dfs(l,r,root:longint):longint;var i,j,mid:longint;begin mid:=(l+r) shr 1; if col[root]=0 then exit(0); if col[root]>0 then begin if not(visit[col[root]]) then begin visit[col[root]]:=true; exit(1); end else exit(0); end; exit(dfs(l,mid,root*2)+dfs(mid+1,r,root*2+1));end;begin read(t); while t>0 do begin dec(t); read(n); for i:=1 to n do begin read(a[i],b[i]); v[i]:=a[i]; v[n+i]:=b[i]; end; qsort(1,2*n); j:=1; for i:=2 to 2*n do if v[i]<>v[i-1] then begin inc(j); v[j]:=v[i]; end; for i:=1 to j do h[v[i]]:=i; fillchar(col,sizeof(col),0); for i:=1 to n do begin update(1,j,h[a[i]],h[b[i]],1,i); end; fillchar(visit,sizeof(visit),false); writeln(dfs(1,j,1)); end;end.
- POJ 2528(数据有误的线段树)
- 数据结构图篇(自己容易理解有误的地方)
- strlen()有误的问题
- poj 2528 线段树数据离散化+区间更新
- poj 2528 线段树
- POJ - 2528 线段树
- POJ 2528 线段树
- poj 2528 Mayor's posters(线段树 二分 大数据离散化 区间更新)
- 关于最近遇到的数据提交时遇到的问题(新人,若有误,请指正)
- POJ 2528 (线段树 离散化)
- poj-2528(线段树+离散化)
- poj 2528 (线段树+离散化)
- poj 2528 线段覆盖 求能看到的线段有几段 (线段切割) poj 3277 (矩形切割)
- POJ 2528 线段树+离散化(水水的线段树+略复杂的离散化)
- 分账和无协议商户数据有误的处理过程
- poj 2777(线段树)
- poj 2777(线段树)
- poj 3264 ( 线段树)
- Linux系统下查看目录大小
- Eclipse+ADT进行Android应用程序的代码签名
- 关于计算java程序运行时间
- 零碎记录
- 动态规划算法及代码
- POJ 2528(数据有误的线段树)
- 对传奇的几个困惑
- SQL Server 2005端口配置
- 递归方法实现归并排序
- PHP的三种HTTP请求
- 论传奇的没落
- afx_msg作用与afx_前缀说明
- 1021 最大特征值
- B-tree在外部存储和数据库索引中的应用