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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

BZOJ 2957 楼房重建 (分块)

發布時間:2023/12/19 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ 2957 楼房重建 (分块) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題解:分塊,然后暴力維護每一塊上升序列,注意是不是最長上升序列,二分查找第二塊中大于第一塊的最后一個上升序列中的數。

   注意:每一塊的大小不要用√n會T掉的,把塊的大小設為500-600都可以(T了一頁了)。或者你用線段樹去寫。

  

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <map> #include <queue> #include <vector> #include <cstring> #include <iomanip> #include <set> #include<ctime> //#include<unordered_map> //CLOCKS_PER_SEC #define se second #define fi first #define ll long long #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define Pii pair<int,int> #define Pli pair<ll,int> #define ull unsigned long long #define pb push_back #define fio ios::sync_with_stdio(false);cin.tie(0) const int N=1e5+10; const ull base=163; const int INF=0x3f3f3f3f; using namespace std;int h[N]; struct node {int top,sta[600]; }p[600]; bool cmp(int x,int y){if(!y)return h[x]>0;return 1LL*y*h[x]>1LL*x*h[y]; } int main(){int n,m;scanf("%d%d",&n,&m);int sz=550;for(int i=1;i<=m;i++){int x;scanf("%d",&x);scanf("%d",&h[x]);int l=x/sz*sz;int r=min(n+1,(x/sz+1)*sz);p[x/sz].top=0;for(int i=l;i<r;i++){if(cmp(i,p[x/sz].sta[p[x/sz].top])){p[x/sz].sta[++p[x/sz].top]=i;}}int last=0,ans=0;for(int i=0;i<=(n)/sz;i++){int l=1,r=p[i].top;int op=0;while (l<=r) {int mid=(l+r)>>1;if(cmp(p[i].sta[mid],last)){r=mid-1;op=mid;}else{l=mid+1;}}if(op){last=p[i].sta[p[i].top];ans+=p[i].top-op+1;}}printf("%d\n",ans);}return 0; }

?

轉載于:https://www.cnblogs.com/Mrleon/p/9051784.html

總結

以上是生活随笔為你收集整理的BZOJ 2957 楼房重建 (分块)的全部內容,希望文章能夠幫你解決所遇到的問題。

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