日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 4533(树状数组区间更新+单点查询)

發布時間:2025/3/16 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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(树状数组区间更新+单点查询)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。