bzoj1935 [Shoi2007]tree Gardener's troubles

Source: Internet
Author: User

Description a long time ago, there was a beautiful country on the distant continent. The king who ruled this beautiful country was a gardener who planted various exotic flowers in his royal garden. One day the King strolled in the garden, thoughtfully, and he asked a gardener, "Recently I was thinking about a question, if we put the flower bed in six hexagonal shape, then ..." "Then essentially it is a depth-first search, sire," and the gardener bowed deeply to the king. "Well ... I heard that there is a monster called nine-head snake, it is very greedy apple tree ... " "Yes, obviously this is a classic dynamic programming problem that we have discovered in the N-dollar 4002, sire." "Damn, what the hell are you?" "Your Majesty propitiate, this line of our work is often inexplicably asked about the topics related to Oi, and I am also in case of prevention!" "The dignity of the king has been hurt, and it is intolerable. It seems that the general difficulty is difficult to fail the gardener, the King finally intends to use wheels off to consume his strength: "Young man, in my garden each tree can be expressed in an integer coordinate, for a moment, my knights will come round to ask you how many trees in a matrix, if you can not answer immediately, you are ready to leave! "After that, the king went out in a huff. The gardener was dumbfounded, and he was unprepared for such a problem. Fortunately, as the President of the National Gardener Conservation Union, you can be his last straw. The first line of input has two integers n,m (0≤n≤500000,1≤m≤500000). n the total number of trees representing the royal garden, M represents the number of times the Knights inquired. The next n rows of the file, each row has two integer xi,yi, representing the coordinates of the tree I (0≤xi,yi≤10000000). The last m line of the file, each line has four integer AJ,BJ,CJ,DJ, which indicates the J-question, where the asked rectangle is (AJ,BJ) is the lower-left coordinate, and (CJ,DJ) is the upper-right coordinate. Output outputs a total of M rows, one integer per line, which answers the number of trees in the rectangle bounded by the King (AJ,BJ) and (CJ,DJ). Sample Input3 1
0 0
0 1
1 0
0 0 1 1
Sample Output3a bit of egg ache ... Originally thought to be a two-dimensional tree-like array of naked questions, the results found that will explodethe changes and queries are sorted from small to large by x-coordinates, and the y-coordinate is separated into a one-dimensional tree array to do
#include <cstdio> #include <iostream> #include <algorithm> #include <cstdlib> #define LL Long Long#define N 1000010using namespace std;struct que{int x,y,rnk,opr;} q[5*n];inline BOOL operator < (const que &a,const que &b) {return a.x<b.x| | A.X==B.X&AMP;&AMP;A.OPR&LT;B.OPR;} int n,m,cnt,cnt2;int x[n],y[n],a[n],b[n],c[n],d[n];int Dat[3*n];int ans[n][5];int c[3*n];inline ll read () {ll x=0,f=1;c    Har Ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline int bsearch (int x) {int L=1,r=cnt;while (l<=r) {int mid= (l+r) >>1;if (X==dat[mid]) return mid;if (x>dat[ Mid]) {l=mid+1;} else r=mid-1;}} inline int lowbit (int x) {return x& (-X);} inline int Add (int x,int d) {for (int i=x;i<=cnt;i+=lowbit (i)) C[i]+=d;} inline int Ask (int x) {int sum=0;for (int i=x;i;i-=lowbit (i)) Sum+=c[i];return sum;} int main () {n=read (); M=read (); for (int i=1;i<=n;i++) {x[i]=read (); Y[i]=read ();  Dat[++cnt]=y[i]; }for (int i=1;i<=m;i++) {a[i]=read (); B[i]=read (); C[i]=read ();d [I]=read ();d at[++cnt]=b[i];d at[++cnt]=d[i];} Sort (dat+1,dat+cnt+1); for (int i=1;i<=n;i++) {y[i]=bsearch (y[i]); q[++cnt2].x=x[i];q[cnt2].y=y[i];} for (int i=1;i<=m;i++) {b[i]=bsearch (b[i]);d [I]=bsearch (D[i]); q[++cnt2].x=c[i];q[cnt2].y=d[i];q[cnt2].rnk=i;q[ cnt2].opr=1;q[++cnt2].x=a[i]-1;q[cnt2].y=d[i];q[cnt2].rnk=i;q[cnt2].opr=2;q[++cnt2].x=c[i];q[cnt2].y=b[i]-1;q[ cnt2].rnk=i;q[cnt2].opr=3;q[++cnt2].x=a[i]-1;q[cnt2].y=b[i]-1;q[cnt2].rnk=i;q[cnt2].opr=4;} Sort (q+1,q+cnt2+1), for (int i=1;i<=cnt2;i++) {if (Q[I].OPR) Ans[q[i].rnk][q[i].opr]=ask (Q[I].Y), else Add (q[i].y,1 );} for (int i=1;i<=m;i++) printf ("%d\n", Ans[i][1]+ans[i][4]-ans[i][2]-ans[i][3]);}

  

bzoj1935 [Shoi2007]tree Gardener's troubles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.