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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

bzoj4919 大根堆

發布時間:2023/12/13 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bzoj4919 大根堆 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

考慮二分求序列LIS的過程。

g[i]表示長度為i的LIS最小以多少結尾。

對于每個數,二分尋找插入的位置來更新g數組。

放到樹上也是一樣,額外加上一個合并兒子的過程。

發現兒子與兒子直接是互不影響的,可以直接合并。

用啟發式合并set來維護這個g數組,復雜度O(nlogn^2)。

#include<iostream> #include<cctype> #include<cstdio> #include<cstring> #include<string> #include<set> #include<cmath> #include<ctime> #include<cstdlib> #include<algorithm> #define N 2200000 #define L 2000000 #define eps 1e-7 #define inf 1e9+7 #define ll long long using namespace std; inline int read() {char ch=0;int x=0,flag=1;while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}return x*flag; } struct edge {int to,nxt; }e[N*2]; int num=-1,head[N]; inline void add(int x,int y) {e[++num]=(edge){y,head[x]};head[x]=num;e[++num]=(edge){x,head[y]};head[y]=num; } int w[N]; multiset<int>s[N]; multiset<int>::iterator it; void merge(int x,int y)//add y to x {if(s[x].size()<s[y].size())swap(s[x],s[y]);while(!s[y].empty()){it=s[y].begin();s[x].insert(*it);s[y].erase(it);} } void dfs(int x,int fa) {for(int i=head[x];i!=-1;i=e[i].nxt){int to=e[i].to;if(to==fa)continue;dfs(to,x);merge(x,to);}it=s[x].lower_bound(w[x]);if(it!=s[x].end())s[x].erase(it);s[x].insert(w[x]); } int main() {memset(head,-1,sizeof(head));int n=read(),x;for(int i=1;i<=n;i++){w[i]=read();x=read();if(i!=1)add(i,x);}dfs(1,1);printf("%d",(int)s[1].size());return 0; }

轉載于:https://www.cnblogs.com/Creed-qwq/p/10078893.html

總結

以上是生活随笔為你收集整理的bzoj4919 大根堆的全部內容,希望文章能夠幫你解決所遇到的問題。

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