ZOJ 1610
来源:互联网 发布:忙与闲 知乎 编辑:程序博客网 时间:2024/06/05 11:18
/*Count the Colors区间覆盖*/#include<cstdio>#include<cstring>#include<vector>#include<algorithm>using namespace std;#define lson (pos<<1)#define rson (pos<<1|1)const int maxn = 8888;const int maxd = 8001;int cover[maxn << 2];int vis[maxn];struct Line{ int l,r; Line(int l,int r):l(l),r(r){}; friend bool operator < (Line p,Line q){ return p.l < q.l; }};vector<Line>G[maxn];void build(int l,int r,int pos){ cover[pos] = -1; if(l == r) return; int mid = (l + r) >> 1; build(l,mid,lson); build(mid + 1,r,rson);}void pushdown(int pos){ if(cover[pos] != -1){ cover[lson] = cover[rson] = cover[pos]; cover[pos] = -1; }}void update(int L,int R,int l,int r,int pos,int d){ if(l <= L && R <= r){ cover[pos] = d; return; } pushdown(pos); int mid = (L + R) >> 1; if(l <= mid) update(L,mid,l,r,lson,d); if(r > mid) update(mid + 1,R,l,r,rson,d);}void query(int l,int r,int pos){ if(cover[pos] != -1){ G[cover[pos]].push_back(Line(l,r)); return; } if(l == r) return; pushdown(pos); int mid = (l + r) >> 1; query(l,mid,lson); query(mid + 1,r,rson);}int main(){ int n; while(scanf("%d",&n) != EOF){ memset(vis,0,sizeof(vis)); for(int i = 0; i < maxd; i++) G[i].clear(); build(0,maxd,1); for(int i = 0; i < n; i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); y --; update(0,maxd,x,y,1,z); } query(0,maxd,1); for(int i = 0; i < maxd; i++){ if(G[i].size() != 0){ printf("%d",i); int cnt = 1; for(int j = 1; j < G[i].size(); j++){ if(G[i][j].l != G[i][j - 1].r + 1) cnt ++; } printf(" %d\n",cnt); } } puts(""); } return 0;}
0 0
- ZOJ 1610
- zoj 1610
- ZOJ 1610
- ZOJ 1610
- zoj--1610
- zoj 1610
- [ZOJ] 1610
- zoj 1610 线段树
- zoj 1610 线段树
- ZOJ 1610 解题报告
- ZOJ ACM 1610(JAVA)
- ZOJ 1610 线段树
- ZOJ-1610(区间染色)
- zoj 1610 线段树
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ONOS Blackbird性能评估
- SQLite实例——dummynote(记事本)
- Windows Tinyxml读取xml文件小结
- Firefox及Chrome访问Https类型Web站点报错
- (struts2) spring mvc + mybatis + maven整合
- ZOJ 1610
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- 第七周项目4——String类的构造
- ASP.NET ViewState详解
- hdu 1032 The 3n + 1 problem (打表)
- oracle中exp,imp的使用详解
- java.util.Collections
- EJB JPA实例
- [乐意黎原创] glassfish里抛出Note: string:///XXX_jsp.java from uses unchecked or unsafe operations.