[ZOJ] 1610
来源:互联网 发布:java基础在线测试 编辑:程序博客网 时间:2024/06/04 19:43
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.
Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.
Sample Input
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
#include <bits/stdc++.h>using namespace std;const int N = 10010;struct Tree{int l;int r;int c;int lazy;};Tree tree[N * 4];int n;int ma[N];int cnt[N];void build(int x, int l, int r){tree[x].l = l;tree[x].r = r;tree[x].c = -1;tree[x].lazy = -1;if(l == r){return;}else{int mid = l + ((r - l) >> 1);build(x << 1, l, mid);build(x << 1 | 1, mid + 1, r);}}void down(int x){int t = tree[x].lazy;if(t != -1){tree[x].lazy = -1;tree[x << 1].c = t;tree[x << 1 | 1].c = t;tree[x << 1].lazy = t;tree[x << 1 | 1].lazy = t;}}void update(int x, int l, int r, int v){int ll = tree[x].l;int rr = tree[x].r;if(l == ll && r == rr){tree[x].lazy = v;tree[x].c = v;return ;}if(l > r){return ;}else{int mid = ll + ((rr - ll) >> 1);down(x);update(x << 1, l, min(mid, r), v);update(x << 1 | 1, max(l, mid + 1), r, v);}}void quary(int x, int l, int r){if(l == r){ma[l] = tree[x].c;}else{int mid = l + ((r - l) >> 1); down(x);quary(x << 1, l, mid);quary(x << 1 | 1, mid + 1, r);}}int main(int argc, char const *argv[]){ int mark;while(scanf("%d", &n) == 1){ memset(cnt, 0, sizeof(cnt));build(1, 0, N);for(int i = 0; i < n; i ++){int l, r, v;scanf("%d%d%d", &l, &r, &v);update(1, l, r - 1, v);}quary(1, 0, N);if(ma[0] != -1){ cnt[ma[0]] ++;}for(int i = 1; i < N; i ++){ if(ma[i] == -1){ continue; } while(ma[i] == ma[i - 1]){ i ++; } cnt[ma[i]]++;}for(int i = 0; i < N; i ++){ if(cnt[i]){ printf("%d %d\n", i, cnt[i]); }}printf("\n");}return 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
- Aliyun共享型主机打开Shadowsocks端口访问
- 1006求正整数的位数及各位数字和
- Android四大组件之BroadcastReceiver
- java重写equals方法需要注意的几点
- idea Spring-boot 项目上传自定义选择配置properties文件
- [ZOJ] 1610
- 论三元九运和二元八运
- 关于JS中的继承(一)
- 杨辉三角
- 解决Centos系统ifconfig不显示ipv4的问题
- POJ 1696 Space Ant <计算几何>
- CCF-训练50题-NO.10-恺撒Caesar密码
- 刚刚注册了CSDN,接下来我将会和大家逐步分享我的开源设计作品
- spring中bean配置和bean注入