Topic introduction
Good aesthetic and lyrical words (ノ へ  ̄,)
Google Translation:
Fleeting time will not blur my memory of you. Is it really four years since I first saw you? I still clearly remember that four years ago, in the beautiful Zhuhai Campus, from the moment you saw your smile, when you walked out of the classroom and turned around, the soft sunset glow shone on your ruddy cheeks. I know, I know I'm drunk with you. Then, after months of observation and snooping, your demeanor and wisdom, your attitude towards life and your vision for the future are deeply imprinted in my memory. You are the charming sunshine girl I have always dreamed of spending the rest of my life with her. Alas, in fact, you are far beyond my wildest dream. I don't know how to bridge the gap between you and me. So I have no plan, just wait, wait for a suitable opportunity.
These days, I'm leaving my friends, roommates and classmates one after another. I still can't believe it. With a wave, these familiar faces will soon disappear from our lives and become memories. I'm moving out of school tomorrow. And you are planning to fly away, pursue the future and realize your dreams. If there were no fate and luck, maybe we wouldn't see each other again. So tonight, I'm wandering in your dormitory building, hoping to meet you there. But paradoxically, your presence must make my heart beat faster, and my clumsy tongue may not be able to spit out a word. I can't remember how many times I passed by your dormitories in Zhuhai and Guangzhou. Every time, I was eager to see you on the balcony and your figure on the window. I don't remember how many times the idea came to my mind: ask her to go out to dinner or at least talk. But every time I think of your excellence and my ordinary, timidity is better than courage, I leave silently.
Graduation means the end of college life and the end of these glorious and romantic years. Your lovely smile is the driving force of my hard work. This single love will be engraved in the bottom of my heart. Graduation also means the beginning of a new life and leaves footprints on the road to light. I really hope you are happy every day abroad and everything goes well. At the same time, I will try to get rid of childishness and become more mature. In reality, pursuing my love and happiness will be an ideal I have never given up.
Goodbye, my princess!
If one day, somewhere, there is a chance to get together, even white haired men and women, at that time, I hope we can become good friends, proudly share this memory and rekindle the feeling of youth and happiness. If this opportunity will never come, I hope I am a star in the sky, twinkling outside your window, bless you in the distance, like a friend, accompany you every night, share sweet dreams, or spend nightmares together.
Here's the problem: suppose the sky is flat. All the stars are on it at (x, y). Each star has a scale of 1 to 100, representing its brightness. 100 is the brightest and 1 is the weakest. A window is a rectangle with edges parallel to the X or Y axis. Your task is to tell me where to put the window in order to maximize the total brightness of the stars in the window. Note that stars at the edge of the window are not counted. The window can be translated but not rotated.
Back to business: analysis
Given that the size and shape of the rectangle are fixed, we can consider selecting a vertex to determine the position of the rectangle. Here, it is the vertex in the upper right corner by default, so we can make a rectangle of the same size with the position of each star as the lower left corner.
If the upper right corner of the rectangle is within the scope of the star rectangle (according to the meaning of the question, excluding the stars by the window), the stars will be caught.
Basic implementation:
- Input data and construct scan line model;
- De reordering;
- Build a line segment tree according to the scan line;
- Add each star into the line segment tree in turn and fight the challenge arena to find the answer.
AC code
#include<bits/stdc++.h> using namespace std; const int maxn=10005; int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } struct star{ int x,y,z; int c; void input(){ x=read();y=read();c=read(); } void output(){ printf(" x = %-2d, y = %-2d, z = %-2d, c = %-2d\n",x,y,z,c); } friend bool operator<(star fir,star sec){ return fir.x<sec.x||(fir.x==sec.x&&fir.c<sec.c); } }a[maxn<<1]; int b[maxn<<1]; int n,w,h; struct segment_tree{ int l,r; int val; int lazy; }tr[maxn<<4]; //#define put printf(" [%d, %d] %d, %d\n",tr[k].l,tr[k].r,tr[k].val,tr[k].lazy) void build(int k,int l,int r){ tr[k].l=l; tr[k].r=r; tr[k].val=tr[k].lazy=0; if(l==r)return ; int mid=(l+r)>>1; build(k<<1,l,mid); build(k<<1|1,mid+1,r); } void push_down(int k){ tr[k<<1].lazy+=tr[k].lazy; tr[k<<1].val+=tr[k].lazy; tr[k<<1|1].lazy+=tr[k].lazy; tr[k<<1|1].val+=tr[k].lazy; tr[k].lazy=0; } void push_up(int k){ tr[k].val=max(tr[k<<1].val,tr[k<<1|1].val); } void change(int k,int l,int r,int c){ if(l<=tr[k].l&&tr[k].r<=r){ tr[k].val+=c; tr[k].lazy+=c; // put; return ; } if(tr[k].lazy)push_down(k); int mid=(tr[k].l+tr[k].r)>>1; if(l<=mid)change(k<<1,l,r,c); if(r>mid)change(k<<1|1,l,r,c); push_up(k); // put; } int main(){ while(scanf("%d%d%d",&n,&w,&h)!=EOF){ for(int i=1;i<=n;i++){ int k=i<<1; a[k-1].input(); a[k].x=a[k-1].x+w; b[k-1]=a[k].y=a[k-1].y; b[k]=a[k].z=a[k-1].z=a[k-1].y+h-1; a[k].c=-a[k-1].c; // a[k-1].output(); // a[k].output(); // printf(" b[%d] = %d\n b[%d] = %d\n",k-1,b[k-1],k,b[k]); } n<<=1; sort(b+1,b+1+n); int m=unique(b+1,b+1+n)-(b+1); // printf(" m = %d\n",m); for(int i=1;i<=n;i++){ a[i].y=lower_bound(b+1,b+1+m,a[i].y)-b; a[i].z=lower_bound(b+1,b+1+m,a[i].z)-b; // printf(" [%d, %d)\n",a[i].y,a[i].z); } sort(a+1,a+1+n); // for(int i=1;i<=n;i++)a[i].output(); build(1,1,m); int ans=0; for(int i=1;i<=n;i++){ change(1,a[i].y,a[i].z,a[i].c); ans=max(ans,tr[1].val); } printf("%d\n",ans); } return 0; }