Reprint Please specify the source Thank you: http://blog.csdn.net/vmurder/article/details/42918883
Test instructions: Go to the Bzoj and see for yourself.
But in short, asking is asking
It means that the rainfall in x years does not exceed Y years, and the rainfall for any y
Solving the puzzle: Then the first discretization, and then add the definite year to the line of the tree, a little mess on the past.
But,,, the discussion is disgusting!!
Detailed reference code, write very clearly (not clear how a This problem)
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 151000using namespace Std;struct Lsh{int X,Y,ID;//ID/2 asked, even L-odd rbool operator < (const LSH &a) Const{return x<a. x;}} Lsh[n];int n,m;int ql[n],qr[n];struct segment_tree{int l,r,size,x;} S[n<<2];int val[n];inline void pushup (int note) {S[note].x=max (s[note<<1].x,s[note<<1|1].x); s[ Note].size=s[note<<1].size+s[note<<1|1].size;} void build (int note,int l,int r) {s[note].l=l,s[note].r=r;if (l==r) return; int Mid=l+r>>1;build (note<<1,l, mid), build (Note<<1|1,mid+1,r);} inline void Add (int note,int pos,int x) {if (S[NOTE].L==S[NOTE].R) {S[note].size=1;s[note].x=x;val[pos]=x;return;} int Mid=s[note].l+s[note].r>>1;if (POS<=MID) Add (note<<1,pos,x); else add (note<<1|1,pos,x); Pushup (note);} inline int query (int note,int l,int r,int &ans) {if (S[NOTE].L==L&&R==S[NOTE].R) {Ans=max (ans,s[note].x); return s[note].size;} int mid=S[note].l+s[note].r>>1;if (R<=MID) return query (Note<<1,l,r,ans), else if (l>mid) return query (note <<1|1,l,r,ans), Else return query (Note<<1,l,mid,ans) +query (Note<<1|1,mid+1,r,ans);} int main () {freopen ("test.in", "R", stdin), int i,j,k;for (scanf ("%d", &n), i=1;i<=n;i++) scanf ("%d%d", &lsh[i ].X,&LSH[I].Y); for (scanf ("%d", &m), i=1;i<=m;i++) {scanf ("%d%d", &lsh[n+i*2-1].x,&lsh[n+i*2]); lsh[n+i*2-1].id=i*2,lsh[n+i*2].id=i*2+1;} N+=m*2;sort (lsh+1,lsh+n+1); int dis,now=0;for (i=1;i<=n;i++) {dis=lsh[i].x-lsh[i-1].x;if (dis==1) Now++;else if ( dis>1) Now+=2;else if (i==1) now++;if (lsh[i].id) {if (lsh[i].id&1) Qr[lsh[i].id>>1]=now;else ql[lsh[i].id >>1]=now;lsh[i].id=0;} else Lsh[i].id=now;} Build (1,1,now), for (i=1;i<=n;i++) if (lsh[i].id) Add (1,lsh[i].id,lsh[i].y); int ans,flag;for (i=1;i<=m;i++) {// It means that the rainfall in X years does not exceed Y years, and the rainfall for any y<z<x,z year is strictly less than x years//left >= right > int size=0,vll=val[ql[i]],vrl=val[qr[i]];if (qr[i]-ql[i] >1) {size=query (1,ql[i]+1,qr[i]-1,ans=0); flag= (size==qr[i]-ql[i]-1);//Two none assigned if (vll==0&&vrl==0) {//can only be maybe, because this random tune. Puts ("maybe");} Left no value, right has value else if (VLL==0&&VRL) {///R>mid can meet condition if (flag| | flag==0) {if (Vrl>ans) puts ("maybe"); else puts ("false");} /*else {if (Vrl>ans) puts ("Maybe"), and//Even if mid is unsure, but at least one of the lowest values else puts ("false");//The following large set of conditions with this}*/}//left value, right not value else if (vll &&vrl==0) {///L>=r>mid R may be very messy//so at least l>midif required (flag| | flag==0) {//This judging condition is a bit severe, thought is this,//but can be omitted. if (Vll>ans) puts ("maybe"), Else puts ("false");}} Two are assigned, then L>=r>mid. else {//L>=R>MIDIF (flag) {if (Vll>=vrl&&vrl>ans) puts ("true"); else puts ("false");} else {if (Vll>=vrl&&vrl>ans) puts ("maybe");//life, with its own day set else puts ("false"); }}}else {if (VLL&&VRL) {if (VRL<=VLL) puts ("true"); else puts ("false");} Else puts ("maybe");}} return 0;}
POJ Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 151000using namespace Std;struct Lsh{int X,Y,ID;//ID/2 asked, even L-odd rbool operator < (const LSH &a) Const{return x<a. x;}} Lsh[n];int n,m;int ql[n],qr[n];struct segment_tree{int l,r,size,x;} S[n<<2];int val[n];void init () {memset (s,0,sizeof s); memset (val,0,sizeof val); memset (lsh,0,sizeof lsh);} inline void pushup (int note) {S[note].x=max (s[note<<1].x,s[note<<1|1].x); s[note].size=s[note<<1] . Size+s[note<<1|1].size;} void build (int note,int l,int r) {s[note].l=l,s[note].r=r;if (l==r) return; int Mid=l+r>>1;build (note<<1,l, mid), build (Note<<1|1,mid+1,r);} inline void Add (int note,int pos,int x) {if (S[NOTE].L==S[NOTE].R) {S[note].size=1;s[note].x=x;val[pos]=x;return;} int Mid=s[note].l+s[note].r>>1;if (POS<=MID) Add (note<<1,pos,x); else add (note<<1|1,pos,x); Pushup (note);} inline int query (int note,int l,int r,int &ans) {if (s[noTE].L==L&&R==S[NOTE].R) {Ans=max (ans,s[note].x); return s[note].size;} int mid=s[note].l+s[note].r>>1;if (R<=MID) return query (Note<<1,l,r,ans); else if (L>mid) return Query (Note<<1|1,l,r,ans), Else return query (Note<<1,l,mid,ans) +query (Note<<1|1,mid+1,r,ans);} int main () {int I,j,k;while (1) {init (); for (scanf ("%d", &n), i=1;i<=n;i++) scanf ("%d%d", &lsh[i].x,&lsh[ I].Y); for (scanf ("%d", &m), i=1;i<=m;i++) {scanf ("%d%d", &lsh[n+i*2-1].x,&lsh[n+i*2]); lsh[n+i*2-1]. id=i*2,lsh[n+i*2].id=i*2+1;} N+=m*2;if (n==0) return 0;sort (lsh+1,lsh+n+1); int dis,now=0;for (i=1;i<=n;i++) {dis=lsh[i].x-lsh[i-1].x;if (dis==1 ) Now++;else if (dis>1) Now+=2;else if (i==1) now++;if (lsh[i].id) {if (lsh[i].id&1) qr[lsh[i].id>>1]=now; else ql[lsh[i].id>>1]=now;lsh[i].id=0;} else Lsh[i].id=now;} Build (1,1,now), for (i=1;i<=n;i++) if (lsh[i].id) Add (1,lsh[i].id,lsh[i].y); int ans,flag;for (i=1;i<=m;i++) {// It means that the rainfall in x years does not exceed Y years, and the rainfall for any y<z<x,z year is strictly less than x years//left >= right > INT Size=0,vll=val[ql[i]],vrl=val[qr[i]];if (qr[i]-ql[i]>1) {size=query (1,ql[i]+1,qr[i]-1,ans=0); flag= (SIZE==QR [i]-ql[i]-1];//Two none assigned if (vll==0&&vrl==0) {//can only be maybe, because this random tune. Puts ("maybe");} Left no value, right has value else if (VLL==0&&VRL) {///R>mid can meet condition if (flag| | flag==0) {if (Vrl>ans) puts ("maybe"); else puts ("false");} /*else {if (Vrl>ans) puts ("Maybe"), and//Even if mid is unsure, but at least one of the lowest values else puts ("false");//The following large set of conditions with this}*/}//left value, right not value else if (vll &&vrl==0) {///L>=r>mid R may be very messy//so at least l>midif required (flag| | flag==0) {//This judging condition is a bit severe, thought is this,//but can be omitted. if (Vll>ans) puts ("maybe"), Else puts ("false");}} Two are assigned, then L>=r>mid. else {//L>=R>MIDIF (flag) {if (Vll>=vrl&&vrl>ans) puts ("true"); else puts ("false");} else {if (Vll>=vrl&&vrl>ans) puts ("maybe");//life, with its own day set else puts ("false"); }}}else {if (VLL&&VRL) {if (VRL<=VLL) puts ("true"); else puts ("false");} Else puts ("maybe");}} Puts ("");} return 0;}
"BZOJ1067" "POJ2637" Worstweather ever "SCOI2007" rainfall segment tree + nausea Discussion