标签:output spec could not rest memset 线段 sizeof color ++
Description
Input
Output
Sample Input
1 5 1 4 2 6 8 10 3 4 7 10
Sample Output
4
Source
#include <cstdio> #include <iostream> #include <string> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long int t, n, ans; int a[400000+8], pos[100000+8][2]; bool sign[400000+8]; struct edge///离散 { int l, r; }e[400000+8]; struct node { int l, r, num; }tree[400000+8]; void build(int i, int l, int r)///建树 { tree[i].l = l; tree[i].r = r; tree[i].num = 0; if(tree[i].l == tree[i].r)///tree[i].l与l无区别,tree[i].r与r无区别 return; int mid = (tree[i].l + tree[i].r) / 2;///tree[i].l与l无区别,tree[i].r与r无区别 build(i * 2, l, mid); build(i * 2 + 1, mid + 1, r); } void push_down(int i)///向下传递num的值 { if(tree[i].num != 0) { tree[i * 2].num = tree[i * 2 + 1].num = tree[i].num; tree[i].num = 0; } return; } void pls(int i, int l, int r, int k)///区间修改 { if(tree[i].l >= l && tree[i].r <= r) { tree[i].num = k; return; } push_down(i); int mid = (tree[i].l + tree[i].r) / 2;///tree[i].l与l无区别,tree[i].r与r无区别 if(l <= mid) pls(i * 2, l, r, k); if(mid < r) pls(i * 2 + 1, l, r, k); } void search(int i) { if(tree[i].num != 0)///如果那个点不等于0 { if(!sign[tree[i].num])///且这个点的值没数过 { sign[tree[i].num] = 1;///标记他数过了 ans++;///总数量加 } return; } search(i * 2); search(i * 2 + 1); } int main() { for(scanf("%d", &t); t--; )/// { memset(sign, 0, sizeof(sign)); memset(a, 0, sizeof(a)); memset(pos, 0, sizeof(pos)); scanf("%d", &n); int id = 1; for(int i = 1; i <= n; i++) { scanf("%d%d", &pos[i][0], &pos[i][1]); a[id++] = pos[i][0]; a[id++] = pos[i][1]; } sort(a + 1, a + id); int index = 1; for(int i = 2; i < id; i++) if(a[i] != a[i-1]) a[++index] = a[i];///到这里数据就变了,也不知道怎么回事 ans = 0; int r = -1; for(int i = 1; i <= n; i++) { e[i].l = lower_bound(a + 1, a + index + 1, pos[i][0]) - a; e[i].r = lower_bound(a + 1, a + index + 1, pos[i][1]) - a; r = max(r, e[i].r);///确定区间最长可到达哪里 } build(1, 1, r); for(int i = 1; i <= n; i++) pls(1, e[i].l, e[i].r, i); search(1); printf("%d\n", ans); } return 0; }
POJ 2528 Mayor's posters(线段树+离散化)
标签:output spec could not rest memset 线段 sizeof color ++
原文地址:https://www.cnblogs.com/RootVount/p/11317063.html