[Cattle off network] [Sokoban discrete segment tree interval coverage]

Judge Online : cattle off network NOIP2018 before training camp - improve group (Session 8) T2

The Label : discrete, tree line interval coverage

ps: this title was changed due to the off-line simulation game, so the following topics describe the adaptation, the subject is still the same.


Title Description

Finally, Sheldon today to fly to Sweden brought the Nobel Prize. As a good friend of Sheldon, Leonard, Penny, Howard, Bernadette, Rajesh will go. However, because of too much baggage, everyone had to luggage piled on the elevator, walk the stairs to the first floor quietly waiting for the elevator.

Unfortunately, luggage piled too high, the elevator doors opened on luggage scattered on the ground. Coincidentally, as if the plane of the floor, the luggage is approximately as rectangular, vertical edges of each tile is defined as coordinate axes respectively, the positive direction of the x-axis to the right, then each side are parallel to each trunk axis, and do not overlap.

Sheldon saw the scene This time, it raises the question to Leonard, if selected by Sheldon a suitcase by Leonard pushed the box to the right moves at the rate of 1 per second units. If you run into a front trunk road, was hit in the trunk will start into motion in that moment of encounter, at a rate of one unit to the right, does not rotate or change the direction of motion. Considering Leonard was a severe asthma patients, so he can only insist k seconds necessary to stop. Leonard and Sheldon wants to know when to stop and the location of all luggage be.

Specifically, a box at a time in a moving state i if and only if: i is the selected box; or there is a box in a moving state j, which is equal to the left boundary of the right boundary of the boxes i and y are at common axis projected length> 0. You can find that in this case, at any moment of each rectangle still do not intersect.

Leonard felt that the issue was too stupid, but I am sorry to refuse (after all, the decade's roommate), then let the old X to answer this question. If the old X successfully answered questions Sheldon, Leonard will make Sheldon will bring together old X to Sweden.

Entry

The first line of two integers n, t and k. Sheldon began to select the input of the t-th baggage. The next four lines each n represents an integer of baggage is the lower left corner coordinates \ ((x1_i, y1_i) \) , top right coordinates \ ((x2_i, y2_i) \) .

Export

Output line n integers, x represents an integer of i-th coordinate of the lower left corner of the k i th second luggage.

You can find just know this value can uniquely determine the position of the trunk.

Sample

Input

5 1 1
1 1 2 3
2 2 3 5
3 4 4 5
4 2 5 5
5 1 6 3

Output

2 3 4 5 6

Hint

For 30% of the data, \ (k≤100 \) .

For another 40% of the data, \ (n≤1000 \) .

To 100% of the data, \ (^ 5,1≤t≤n n ≤ 10, 9 1≤k≤10 ^ \) , all coordinates are \ (- 10 ^ 9 \) and \ (10 ^ 9 \) between.

Data baggage guarantee any two disjoint.

answer

The first is based on (x1 \) \ will sort all the boxes. We just know each box for the first time pushed the time \ (ti \) to calculate the position of the last of each box.

To avoid rubbing off, we started first \ (y2 - \) . Thus as long as two point two sections constituting the ordinate presence intersection indicates collided. Suppose \ (I \) is hit front of it, and \ (I \) can be hit \ (J \) , then \ (ti [j] = min (ti [j], ti [i] + x1 [J] -x2 [I]) \) .

For 70% of the data, direct violence \ (O (N) \) sweeping over the front of the luggage to, the minimum value, the overall time complexity is \ (O (N ^ 2) \) .

Consider how fast to take the minimum, it is clear that can be used tree line to optimize. First ordinate discrete , and then assign a value on some sections of the tree line, this interval is the discrete ordinate. When the query is a query interval in accordance with the minimum vertical coordinate of the current point. What value does exist, the above observations that the formula was, as long as the deposit \ (ti [i] -x2 [ i] \) can be. Tree line supports a range of coverage, the minimum interval queries can be.

This question is over, but the realization there are many details to note:

1. Finally, we must sentence \ (Ti [] <= K \) , is guaranteed to be hit in a predetermined time.

2. Since the segment tree is the assignment interval, the beginning of the lazy lazy tag, must be assigned a minimum value w to a maximum value INF.

3. To open an array of discrete \ (2N \) , because for each box are scattered a \ (y1, y2 \) Total \ (2N \) number. Accordingly, the tree line array size to open \ (8N \) .

4. beginning \ (y2 - \) , to ensure that the situation does not appear grazed.

5. When the exam a very silly doubts: how to ensure the press x1 sort, as long as there ordinate the intersection of two boxes collide, if the front of the box x2> x1 behind a box that does not collide yet, in fact, painting a map to know that this can not simultaneously satisfy both qwq.

code show as below:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,INF=1e9+2;
inline int read(){
    int x=0,e=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')e=-1;c=getchar();}
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*e;
}
struct node{
    int x,y,x2,y2,id;
}o[N];
inline bool cmp(node a,node b){return a.x<b.x;}
int n,s,k,LIM;

struct sgt{
    int l,r,w,lazy;
}b[8*N];
void build(int o,int l,int r){
    b[o].l=l,b[o].r=r,b[o].w=INF,b[o].lazy=INF;
    if(l==r)return;
    int mid=l+r>>1;
    build(o<<1,l,mid);build(o<<1|1,mid+1,r);
}
void down(int o){
    if(b[o].lazy==INF)return ;
    int p=b[o].lazy;
    b[o<<1].w=min(b[o<<1].w,p);b[o<<1|1].w=min(b[o<<1|1].w,p);
    b[o<<1].lazy=min(b[o<<1].lazy,p);b[o<<1|1].lazy=min(b[o<<1|1].lazy,p);
    b[o].lazy=INF;
}
void update(int o,int l,int r,int d){
    if(b[o].l==l&&b[o].r==r){
        b[o].w=min(b[o].w,d);
        b[o].lazy=min(b[o].lazy,d);
        return;
    }
    down(o);
    int mid=b[o].l+b[o].r>>1;
    if(r<=mid)update(o<<1,l,r,d);
    else if(l>mid)update(o<<1|1,l,r,d);
    else{
        update(o<<1,l,mid,d);update(o<<1|1,mid+1,r,d);
    }
    b[o].w=min(b[o<<1].w,b[o<<1|1].w);
}
int query(int o,int l,int r){
    if(b[o].l==l&&b[o].r==r)return b[o].w;
    down(o);
    int mid=b[o].l+b[o].r>>1;
    if(r<=mid)return query(o<<1,l,r);
    else if(l>mid)return query(o<<1|1,l,r);
    return min(query(o<<1,l,mid),query(o<<1|1,mid+1,r));
}
int ti[N],res[N];
int yy[2*N];
int main(){
    n=read(),s=read(),k=read();
    int tmp=0;
    for(register int i=1;i<=n;i++){
        int a=read(),b=read(),c=read(),d=read();
        d--;    
        o[i]=(node){a,b,c,d,i};
        yy[++tmp]=b,yy[++tmp]=d;
    }
    sort(o+1,o+n+1,cmp);
    sort(yy+1,yy+tmp+1);
    LIM=unique(yy+1,yy+tmp+1)-yy-1;
    
    for(register int i=1;i<=n;i++){
        o[i].y=lower_bound(yy+1,yy+LIM+1,o[i].y)-yy;
        o[i].y2=lower_bound(yy+1,yy+LIM+1,o[i].y2)-yy;
    }
    build(1,1,LIM);
    int st;
    for(register int i=1;i<=n;i++)if(o[i].id==s){st=i;break;}
    ti[st]=1;
    update(1,o[st].y,o[st].y2,1-o[st].x2);
    for(register int i=st+1;i<=n;i++){
        int now=query(1,o[i].y,o[i].y2);    
        if(now==INF)continue;
        ti[i]=o[i].x+now;
        update(1,o[i].y,o[i].y2,ti[i]-o[i].x2);
    }
    for(register int i=1;i<=n;i++){
        if(ti[i]&&ti[i]<=k)res[o[i].id]=k-ti[i]+1+o[i].x;
        else res[o[i].id]=o[i].x;
    }
    for(register int i=1;i<n;i++)printf("%d ",res[i]);
    printf("%d\n",res[n]);
} 

Guess you like

Origin www.cnblogs.com/Tieechal/p/11488032.html