POJ
来源:互联网 发布:js array map ie8 编辑:程序博客网 时间:2024/06/06 08:44
POJ - 2528 Mayor's posters
题意就是在墙上贴海报,给你每张海报覆盖的起始位置,求最后能看到几张海报
用线段树来做,-1表示未覆盖的和混合的
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>#include <bitset>#define INF 0x3f3f3f3f#define eps 1e-6#define PI 3.1415926#define mod 1000000009#define base 2333using namespace std;typedef long long LL;const int maxn = 1e5 + 10;const int maxx = 1e3 + 10;inline void splay(int &v) { v=0;char c=0;int p=1; while(c<'0' || c >'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p;}int t, n, x, y, ans, Hash[maxn], aa[maxn<<1];struct edge { int l, r; edge(int l = 0, int r = 0): l(l), r(r) {}} seg[maxn];struct Tree { int l, r, m; int lazy, val;} tr[maxn<<2];void PushDown(int id) { if(tr[id].lazy != -1) { tr[id<<1].lazy = tr[id<<1|1].lazy = tr[id].lazy; tr[id].lazy = -1; }}void build(int id, int l, int r) { tr[id].l = l, tr[id].r = r; tr[id].m = (l+r)>>1; if(l == r) tr[id].lazy = -1; else { build(id<<1, l, tr[id].m); build(id<<1|1, tr[id].m+1, r); tr[id].val = tr[id].lazy = -1; }}void update(int id, int l, int r, int v) { if(l <= tr[id].l && r >= tr[id].r) tr[id].lazy = v; else { PushDown(id); if(l <= tr[id].m) update(id<<1, l, r, v); if(r > tr[id].m) update(id<<1|1, l, r, v); }}void query(int id, int l, int r) { if(tr[id].lazy != -1) { if(aa[tr[id].lazy] == 0) { aa[tr[id].lazy] = 1; ans++; } return ; } if(l == r) return ; else { PushDown(id); if(l <= tr[id].m) query(id<<1, l, r); if(r > tr[id].m) query(id<<1|1, l, r); }}void solve() { splay(t); while(t--) { splay(n); int k = 0, h = 0, m = 1; ans = 0; memset(aa, 0, sizeof(aa)); for(int i = 1; i <= n; i++) { scanf("%d%d", &x, &y); seg[++k] = edge(x, y); Hash[++h] = x, Hash[++h] = y; } sort(Hash+1, Hash+h+1); for(int i = 1; i < h; i++) { if(Hash[i] != Hash[i+1]) Hash[++m] = Hash[i+1]; } build(1, 1, m); for(int i = 1; i <= k; i++) { int L = lower_bound(Hash+1, Hash+m+1, seg[i].l)-Hash; int R = lower_bound(Hash+1, Hash+m+1, seg[i].r)-Hash; update(1, L, R, i); } query(1, 1, m); printf("%d\n", ans); }}int main() { //srand(time(NULL)); //freopen("kingdom.in","r",stdin); //freopen("kingdom.out","w",stdout); solve();}
阅读全文
1 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- c++构造函数抛出异常
- 用python语言写的简易爬虫
- 利用百度贴吧上首页暴力引流小技巧
- JavaScript函数
- android圆环
- POJ
- memcached 的学习
- 函数的可重入和C++中Sendmessage 和 PostMessage 的区别
- 影子寄存器
- css层叠样式表
- 人物名字上莫名有个称号怎么办
- 12000字揭秘阿里连环炮面试
- hdu6052To my boyfriend(子矩阵计数处理)
- 2017 Multi-University Training Contest