hdu 4325

#include<stdio.h>//数据弱线段树延迟更新水过
#define N 100100
struct node {
int x,y,yanchi,num;
}a[N*4];
void build(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].yanchi=0;
a[t].num=0;
if(x==y)
return ;
int temp=t<<1;
int mid=(x+y)/2;
build(temp,x,mid);
build(temp+1,mid+1,y);
}
void update(int t,int x,int y) {
if(a[t].x==x&&a[t].y==y) {
a[t].yanchi++;
return ;
}
a[t].num=a[t].num+y-x+1;
int temp=t<<1;
int mid=(a[t].x+a[t].y)/2;
if(mid<x)
update(temp+1,x,y);
else
if(mid>=y)
update(temp,x,y);
else {
update(temp,x,mid);
update(temp+1,mid+1,y);
}
return;
}
int qury(int t,int h) {
if(a[t].x==h&&a[t].y==h) 
return a[t].num+a[t].yanchi;
a[t].num=a[t].num+a[t].yanchi*(a[t].y-a[t].x+1);
int temp=t<<1;
a[temp].yanchi+=a[t].yanchi;
a[temp+1].yanchi+=a[t].yanchi;
a[t].yanchi=0;
int mid=(a[t].x+a[t].y)/2;
if(mid<h)
return qury(temp+1,h);
else
return qury(temp,h);
}
int main() {
int t,n,m,x,y,i,k,count=0;
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&m);
printf("Case #%d:\n",++count);
build(1,1,100000);
for(i=0;i<n;i++) {
scanf("%d%d",&x,&y);
update(1,x,y);
}
while(m--) {
scanf("%d",&k);
printf("%d\n",qury(1,k));
}
}
return 0;
}

转载于:https://www.cnblogs.com/thefirstfeeling/p/4410923.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值