bzoj4237稻草人
生活随笔
收集整理的這篇文章主要介紹了
bzoj4237稻草人
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳送門
寫了一中午,被自己瓜得無話可說。
cdq的題,然后開始腦補。
寫了第一個版本是考慮一半對另一半的貢獻,貢獻的那一遍維護單調性,沒有考慮查詢的一半的點之間的影響,一直偏大,14pt。
卡掉的數據:
5
1 5
5 4
2 1
3 2
4 3
然后不知道如何腦抽地寫了第二個版本,樹狀數組亂搞,從擋住的地方往上在數組數組里減,然后被重復擋的部分會被多減,一直偏小,31pt
卡掉的數據
5
1 1
4 2
2 3
5 4
5 5
最終屈服于題解,,智商堪憂,,
按x排序,按y分治,考慮下一半對上一半的影響,上一半維護單增的單調棧,相當于知道這個查詢點前一個擋住它的點的位置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數終于突破兩位數了,留戀一下,可喜可賀可喜可賀。
?
轉載于:https://www.cnblogs.com/Achenchen/p/8080789.html
總結
以上是生活随笔為你收集整理的bzoj4237稻草人的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Electron
- 下一篇: 1.4激活函数-带隐层的神经网络tf实战