poj 3263 区间覆盖统计
来源:互联网 发布:李光耀的书 知乎 编辑:程序博客网 时间:2024/04/28 16:59
线段树求区间覆盖,注意去重复区间。
#include<stdio.h>#include<iostream>#include<algorithm>#include<set>#include<string.h>using namespace std;const int maxn=10005;typedef pair<int, int> PII;set <PII> C;int cnt[maxn],N,I,H,R;struct Tree{ int l,r,cov;}t[maxn<<2];#define mid ((t[p].l+t[p].r)>>1)#define ls (p<<1)#define rs ((ls)+1)void build(int p,int l,int r){ t[p].l=l;t[p].r=r;t[p].cov=0; if(l==r) return ; build(ls,l,mid); build(rs,mid+1,r);}void modify(int p,int l,int r){ if(l>r) return ; if(t[p].l==l && t[p].r==r) { t[p].cov++; return; } if(r<=mid) modify(ls,l,r); else if(l>=mid+1) modify(rs,l,r); else { modify(ls,l,mid); modify(rs,mid+1,r); }}void query(int p){ if(t[p].l==t[p].r) { cnt[t[p].l]=t[p].cov; return ; } if(t[p].cov) { t[ls].cov+=t[p].cov; t[rs].cov+=t[p].cov; } query(ls); query(rs);}int main(){// freopen("test.txt","r",stdin); scanf("%d%d%d%d",&N,&I,&H,&R); build(1,1,N); memset(cnt,0,sizeof(cnt)); for(int i=0;i<R;i++) { int a,b; scanf("%d%d",&a,&b); if(a>b) swap(a,b); if(!C.count(PII(a,b))) { C.insert(PII(a,b)); modify(1,a+1,b-1); } } query(1); for(int i=1;i<=N;i++) printf("%d\n",H-cnt[i]); return 0;}
- poj 3263 区间覆盖统计
- poj 3277 区间覆盖
- 【Intervals POJ 区间覆盖】
- poj 2376 区间覆盖
- poj 2777 区间统计
- POJ 1328 区间覆盖 贪心
- poj 2376 贪心(区间覆盖)
- poj 2376(区间覆盖)
- POJ 1089 Intervals 区间覆盖+ 贪心
- POJ 3171(区间覆盖最小代价)
- poj 百练 Intervals 区间覆盖
- poj 2376 最小区间覆盖问题
- POJ 2376 Cleaning Shifts 区间覆盖问题
- poj 1089 贪心之区间覆盖问题
- poj 1716 贪心(整数区间:2-覆盖)
- poj 3171Cleaning Shifts 区间覆盖
- poj 2376 贪心(覆盖区间)
- poj 2376 贪心 区间覆盖问题
- yii视图布局文件
- ubuntu 12.04下安装QQ
- yii联查
- SVN版本库(访问权限)配置实例笔记
- 说明JavaScript 函数间按值传参的一个例子
- poj 3263 区间覆盖统计
- Android游戏开发框架(三)垃圾回收器
- bt5常用命令
- poj 3257 二维dp
- centos6 minimal
- 介绍本人的一个Android项目(附源代码)
- 找重复元素
- Backbone笔记之二(Model/Collection)
- 除夕