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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

洛谷 - P3810 【模板】三维偏序(陌上花开)(CDQ分治套树状数组)

發(fā)布時間:2024/4/11 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 洛谷 - P3810 【模板】三维偏序(陌上花开)(CDQ分治套树状数组) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接:點擊查看

題目大意:給出 n 個點,每個點有三個屬性 a , b , c ,對于每個點 i 來說,求出有多少個 j 滿足 a[ j ] <= a[ i ] && b[ j ] <= b[ i ] && c[ j ] <= c[ i ]

題目分析:三維偏序的模板問題,咕咕咕了有一年的CDQ分治,今天終于補出來了,簡單總結(jié)一下,一維偏序排個序就出來了,二維偏序是對一維排序,另一維用線段樹或樹狀數(shù)組維護,三維的話,第一維排序,第二維用歸并排序維護,第三維用線段樹維護,在歸并排序的過程中計算貢獻就好了

代碼:

#include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<unordered_map> using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=2e5+100;struct Node {int a,b,c,f,w;bool operator==(const Node& t)const{return a==t.a&&b==t.b&&c==t.c;}bool operator<(const Node& t)const{if(a!=t.a)return a<t.a;if(b!=t.b)return b<t.b;return c<t.c;} }a[N],t[N];int c[N],ans[N],n,k;int lowbit(int x) {return x&(-x); }void add(int pos,int val) {while(pos<=k){c[pos]+=val;pos+=lowbit(pos);} }int ask(int pos) {int ans=0;while(pos){ans+=c[pos];pos-=lowbit(pos);}return ans; }void CDQ(int l,int r) {if(l==r)return;int mid=l+r>>1;CDQ(l,mid);CDQ(mid+1,r);int p=l,q=mid+1,tot=l;while(p<=mid&&q<=r){if(a[p].b<=a[q].b){add(a[p].c,a[p].w);t[tot++]=a[p++];}else{a[q].f+=ask(a[q].c);t[tot++]=a[q++];}}while(p<=mid){add(a[p].c,a[p].w);t[tot++]=a[p++];}while(q<=r){a[q].f+=ask(a[q].c);t[tot++]=a[q++];}for(int i=l;i<=mid;i++)add(a[i].c,-a[i].w);for(int i=l;i<=r;i++)a[i]=t[i]; }int unique() {int cnt=0;for(int i=1;i<=n;i++){if(a[i]==a[i-1])a[cnt].w++;elsea[++cnt]=a[i];}return cnt; }int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);scanf("%d%d",&n,&k);int nn=n;for(int i=1;i<=n;i++){scanf("%d%d%d",&a[i].a,&a[i].b,&a[i].c);a[i].w=1;}sort(a+1,a+1+n);n=unique();CDQ(1,n);for(int i=1;i<=n;i++)ans[a[i].f+a[i].w-1]+=a[i].w;for(int i=0;i<nn;i++)printf("%d\n",ans[i]);return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的洛谷 - P3810 【模板】三维偏序(陌上花开)(CDQ分治套树状数组)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。