hdu 4533(树状数组区间更新+单点查询)
生活随笔
收集整理的這篇文章主要介紹了
hdu 4533(树状数组区间更新+单点查询)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給你N個矩形,每個矩形給出左下角坐標,右上角坐標,有M個詢問,每個詢問給出一個時間t,問(0,0),(t,t)的范圍內矩形的面積和(重疊的也算)。
參考博客:http://blog.csdn.net/shiqi_614/article/details/8869676
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=200005; typedef long long LL; struct BIT {LL T[N];int lowbit(int x) {return x&(-x);}void clear(){memset(T,0,sizeof(T));}void add(int st,int ed,LL valu){for(int i=st;i<N;i+=lowbit(i)) T[i]+=valu;for(int i=ed+1;i<N;i+=lowbit(i)) T[i]-=valu;}LL query(int pos){LL sum=0;for(int i=pos;i>0;i-=lowbit(i)) sum+=T[i];return sum;} }A,B,C; void fun(int st,int ed,LL a,LL b,LL c) {A.add(st,ed,a);B.add(st,ed,b);C.add(st,ed,c); } int main() {int t;scanf("%d",&t);while(t--){A.clear(); B.clear(); C.clear();int n,m;scanf("%d",&n);for(int i=0;i<n;i++){LL x1,y1,x2,y2;scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2);if(max(x1,y1)<min(x2,y2))fun(max(x1,y1),min(x2,y2),1,-(x1+y1),x1*y1);if(x2<y2) fun(max(x2,y1)+1,y2,0,-x1+x2,y1*(x1-x2));if(y2<x2) fun(max(y2,x1)+1,x2,0,-y1+y2,x1*(y1-y2));fun(max(x2,y2)+1,N,0,0,(x2-x1)*(y2-y1));}scanf("%d",&m);while(m--){LL t;scanf("%I64d",&t);LL ans=0;ans+=A.query(t)*t*t;ans+=B.query(t)*t;ans+=C.query(t);printf("%I64d\n",ans);}}return 0; }
與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
以上是生活随笔為你收集整理的hdu 4533(树状数组区间更新+单点查询)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu 5101(二分)
- 下一篇: 【高并发解决方案】5、如何设计一个秒杀系