#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define maxn 1100000
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
int tree[maxn<<2];
void pushdown(int rt)
{
if(tree[rt])
{
tree[rt<<1]+=tree[rt];
tree[rt<<1|1]+=tree[rt];
tree[rt]=0;
}
}
void update(int rt,int l,int r,int x,int y)
{
if(x<=l&&y>=r)
{
tree[rt]+=1;
return ;
}
pushdown(rt);
int m=(l+r)>>1;
if(x<=m)
{
update(lson,x,y);
}
if(y>m)
{
update(rson,x,y);
}
}
int query(int rt,int l,int r,int x)
{
if(l==r)
{
return tree[rt];
}
pushdown(rt);
int m=(l+r)>>1;
if(x<=m)
return query(lson,x);
else
return query(rson,x);
}
int main()
{
int n,m;
int a,b,c;
while(scanf("%d",&n)&&n)
{
memset(tree,0,sizeof(tree));
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a,&b);
update(1,1,n,a,b);
}
for(int i=1;i<n;i++)
{
printf("%d ",query(1,1,n,i));
}
printf("%d\n",query(1,1,n,n));
}
return 0;
}
hdu1556 线段树 区间修改
最新推荐文章于 2024-08-21 19:41:42 发布