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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

bzoj4237稻草人

發(fā)布時間:2023/12/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bzoj4237稻草人 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

傳送門

寫了一中午,被自己瓜得無話可說。

cdq的題,然后開始腦補。

寫了第一個版本是考慮一半對另一半的貢獻(xiàn),貢獻(xiàn)的那一遍維護單調(diào)性,沒有考慮查詢的一半的點之間的影響,一直偏大,14pt。

卡掉的數(shù)據(jù):

5

1 5

5 4

2 1

3 2

4 3

然后不知道如何腦抽地寫了第二個版本,樹狀數(shù)組亂搞,從擋住的地方往上在數(shù)組數(shù)組里減,然后被重復(fù)擋的部分會被多減,一直偏小,31pt

卡掉的數(shù)據(jù)

5

1 1

4 2

2 3

5 4

5 5

最終屈服于題解,,智商堪憂,,

按x排序,按y分治,考慮下一半對上一半的影響,上一半維護單增的單調(diào)棧,相當(dāng)于知道這個查詢點前一個擋住它的點的位置pos,從該點往后的單減的棧就是答案。

于是下一半維護單減的棧,二分找到其中第一個x大于pos的x的位置,往后的棧大小就是答案。

//Achen #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<vector> #include<queue> #include<ctime> #include<cmath> const int N=2e5+7; typedef long long LL; using namespace std; int n,xx[N],yy[N],q1[N],q2[N],top1,top2; LL ans;template<typename T> void read(T &x) {char ch=getchar(); x=0; T f=1;while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();if(ch=='-') f=-1,ch=getchar();for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f; }struct node{int x,y;friend bool operator <(const node&A,const node &B) {return A.x<B.x;} }p[N],tp[N];int ef(int x) {int l=1,r=top1,res=0;while(l<=r) {int mid=((l+r)>>1);if(p[q1[mid]].x>x) res=mid,r=mid-1;else l=mid+1;}if(res!=0) res=top1-res+1;return res; }void cdq(int l,int r) {if(l==r) return; int mid=((l+r)>>1),ql=l-1,qr=mid;top1=top2=0;for(int i=l;i<=r;i++) {if(p[i].y<=mid) {tp[++ql]=p[i];while(top1&&p[q1[top1]].y<p[i].y) top1--;q1[++top1]=i;}else {tp[++qr]=p[i];while(top2&&p[q2[top2]].y>p[i].y) top2--;ans+=ef(p[q2[top2]].x);q2[++top2]=i;}}for(int i=l;i<=r;i++) p[i]=tp[i];cdq(l,mid); cdq(mid+1,r); }#define DEBUG int main() { #ifdef DEBUGfreopen("scarecrows.in","r",stdin);freopen("scarecrows.out","w",stdout); #endifread(n);for(int i=1;i<=n;i++) {read(p[i].x); read(p[i].y);xx[i]=p[i].x;yy[i]=p[i].y;}sort(xx+1,xx+n+1);sort(yy+1,yy+n+1);for(int i=1;i<=n;i++) {p[i].x=lower_bound(xx+1,xx+n+1,p[i].x)-xx;p[i].y=lower_bound(yy+1,yy+n+1,p[i].y)-yy;}sort(p+1,p+n+1);cdq(1,n);printf("%lld\n",ans);return 0; } View Code

?

不管怎么說,bzojSolved數(shù)終于突破兩位數(shù)了,留戀一下,可喜可賀可喜可賀。

?

轉(zhuǎn)載于:https://www.cnblogs.com/Achenchen/p/8080789.html

總結(jié)

以上是生活随笔為你收集整理的bzoj4237稻草人的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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