世界是一方小小的邮票,我在这头,AC 在那头

10.07 06:41 100pts

#include<bits/stdc++.h>
#define int long long
#ifndef FRAC_H
#define FRAC_H
using namespace std;
namespace hdk{
class frac{
    public:
        int z,m;
        frac(int x=0,int y=1){
            z=x,m=y;
            fixed();
        }
        frac fixed(){
            int gcd=__gcd(abs(z),abs(m));
            if(m<0){
                m*=-1;z*=-1;
            }
            if(z==0){
                m=1;return *this;
            }
            if(gcd==0) return *this;
            z/=gcd;m/=gcd;
            return *this;
        }
        frac upside(){
            return frac(m,z);
        }
        frac operator = (pair<int,int>A){
            z=A.first;m=A.second;fixed();
            return *this;
        }
        frac operator + (frac A){
            return (frac(z*A.m+m*A.z,m*A.m)).fixed();
        }
        frac operator * (frac A){
            return (frac(z*A.z,m*A.m)).fixed();
        }
        frac operator / (frac A){
            return (*this*A.upside()).fixed();
        }
        frac operator -(){
            return frac(-z,m);
        }
        frac operator -(frac A){
            return *this+(-A);
        }
        bool operator <(const frac &A)const{
            return z*A.m<A.z*m;
        }
        bool operator ==(const frac &A)const{
            return z*A.m==A.z*m;
        }
        bool operator >(const frac &A)const{
            return !(*this==A and *this<A);
        }
};
}
#endif
using namespace std;
int n;
struct ques{
    int op;
    int xa,ya,xb,yb;
}q[100001];
hdk::frac a[400001];
int cnt,ree=1;
map<hdk::frac,int>mp;
bool cmp(const hdk::frac &A,const hdk::frac &B){
    return B<A;
}
inline int maped(pair<int,int> x){
    if(x.second==0) return 1;
    return mp[hdk::frac(x.first,x.second)];
}
struct __ans{
    int ans,minn;
};
struct stree{
    struct tree{
        int l,r;
        int pos,minn;
    }t[1000001];
    #define tol (id*2)
    #define tor (id*2+1)
    #define mid(l,r) mid=((l)+(r))/2
    void build(int id,int l,int r){
        t[id].l=l;t[id].r=r;
        t[id].pos=0;t[id].minn=0;
        if(l==r) return;
        int mid(l,r);
        build(tol,l,mid);
        build(tor,mid+1,r);
    }
    void change(int id,int l,int r,int val,int pos){
        if(l<=t[id].l and t[id].r<=r){
            if(t[id].pos==0 or t[id].minn>=val){
                t[id].pos=pos;
                t[id].minn=val;
            }
            return;
        }
        if(r<=t[tol].r) change(tol,l,r,val,pos);
        else if(l>=t[tor].l) change(tor,l,r,val,pos);
        else{
            change(tol,l,t[tol].r,val,pos);
            change(tor,t[tor].l,r,val,pos);
        }
    }
    __ans ask(int id,int pos){
        if(t[id].l==t[id].r){
            return {t[id].pos,t[id].minn};
        }
        __ans res={};
        if(pos<=t[tol].r) res=ask(tol,pos);
        else res=ask(tor,pos);
        if(t[id].pos==0) return res;
        if(res.ans==0 or t[id].minn<res.minn) return {t[id].pos,t[id].minn};
        else if(t[id].minn==res.minn and t[id].pos>res.ans) return {t[id].pos,t[id].minn};
        return res;
    }
};
stree x,y;
int cal(__ans x,__ans y,int xx,int yy){
    if(x.ans==0) return y.ans;
    if(y.ans==0) return x.ans;
    if(xx==0){
        if(q[x.ans].ya<q[y.ans].ya) return x.ans;
        return y.ans;
    }
    if(yy==0){
        if(q[x.ans].xa<q[y.ans].xa) return x.ans;
        return y.ans;
    }
    if(x.minn*xx==y.minn*yy){
        if(x.ans>y.ans) return x.ans;
        return y.ans;
    }
    if(x.minn*xx<y.minn*yy){
        return x.ans;
    }
    return y.ans;
}
signed main(){
    // freopen("down/raytracing5.in","r",stdin);
    // freopen("out.out","w",stdout);
    freopen("raytracing.in","r",stdin);
    freopen("raytracing.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld",&q[i].op);
        if(q[i].op==1){
            scanf("%lld %lld %lld %lld",&q[i].xa,&q[i].ya,&q[i].xb,&q[i].yb);
            if(q[i].xa) a[++cnt]=hdk::frac(q[i].ya,q[i].xa);
            if(q[i].xb) a[++cnt]=hdk::frac(q[i].ya,q[i].xb);
            if(q[i].xa) a[++cnt]=hdk::frac(q[i].yb,q[i].xa);
        }
        else{
            scanf("%lld %lld",&q[i].xa,&q[i].ya);
            if(q[i].xa) a[++cnt]=hdk::frac(q[i].ya,q[i].xa);
        }
    }
    sort(a+1,a+cnt+1,cmp);
    // cout<<"cth "<<endl;
    for(int i=1;i<=cnt;++i){
        if(i==1 or !(a[i]==a[i-1])){
            mp[a[i]]=++ree;
        }
    }
    x.build(1,1,ree);//cout<<"cth "<<endl;
    y.build(1,1,ree);//cout<<"cth "<<endl;
    for(int i=1;i<=n;++i){
        if(q[i].op==1){
            int r1=maped({q[i].yb,q[i].xa});
            int r2=maped({q[i].ya,q[i].xb});
            int mid=maped({q[i].ya,q[i].xa});
            // cout<<"x change "<<min(r1,mid)<<" "<<max(r1,mid)<<": val="<<q[i].b<<" pos="<<i<<endl;
            x.change(1,min(r2,mid),max(r2,mid),q[i].ya,i);
            // cout<<"y change "<<min(r2,mid)<<" "<<max(r2,mid)<<": val="<<q[i].a<<" pos="<<i<<endl;
            y.change(1,min(r1,mid),max(r1,mid),q[i].xa,i);
        }
        else{
            __ans tmp1=x.ask(1,maped({q[i].ya,q[i].xa}));
            // cout<<"x ask "<<maped({q[i].b,q[i].a})<<" :"<<"val= "<<tmp1.first<<" pos="<<tmp1.second<<endl;
            __ans tmp2=y.ask(1,maped({q[i].ya,q[i].xa}));
            // cout<<"y ask "<<maped({q[i].b,q[i].a})<<" :"<<"val= "<<tmp2.first<<" pos="<<tmp2.second<<endl;
            cout<<cal(tmp1,tmp2,q[i].xa,q[i].ya)<<'\n';
        }
    }
}

10.06 21:34 30pts

#include<bits/stdc++.h>
#define int long long
#ifndef FRAC_H
#define FRAC_H
using namespace std;
namespace hdk{
class frac{
    public:
        int z,m;
        frac(int x=0,int y=1){
            z=x,m=y;
            fixed();
        }
        frac fixed(){
            int gcd=__gcd(abs(z),abs(m));
            if(m<0){
                m*=-1;z*=-1;
            }
            if(z==0){
                m=1;return *this;
            }
            if(gcd==0) return *this;
            z/=gcd;m/=gcd;
            return *this;
        }
        frac upside(){
            return frac(m,z);
        }
        frac operator = (pair<int,int>A){
            z=A.first;m=A.second;fixed();
            return *this;
        }
        frac operator + (frac A){
            return (frac(z*A.m+m*A.z,m*A.m)).fixed();
        }
        frac operator * (frac A){
            return (frac(z*A.z,m*A.m)).fixed();
        }
        frac operator / (frac A){
            return (*this*A.upside()).fixed();
        }
        frac operator -(){
            return frac(-z,m);
        }
        frac operator -(frac A){
            return *this+(-A);
        }
        bool operator <(const frac &A)const{
            return z*A.m<A.z*m;
        }
        bool operator ==(const frac &A)const{
            return z*A.m==A.z*m;
        }
        bool operator >(const frac &A)const{
            return !(*this==A and *this<A);
        }
};
}
#endif
using namespace std;
int n;
struct ques{
    int op;
    int a,b,c,d;
}q[100001];
hdk::frac a[400001];
int cnt,ree=1;
map<hdk::frac,int>mp;
bool cmp(const hdk::frac &A,const hdk::frac &B){
    return B<A;
}
inline int maped(pair<int,int> x){
    if(x.second==0) return 1;
    return mp[hdk::frac(x.first,x.second)];
}
struct stree{
    struct tree{
        int l,r;
        int pos,minn;
    }t[1000001];
    #define tol (id*2)
    #define tor (id*2+1)
    #define mid(l,r) mid=((l)+(r))/2
    void build(int id,int l,int r){
        t[id].l=l;t[id].r=r;
        t[id].pos=0;t[id].minn=0;
        if(l==r) return;
        int mid(l,r);
        build(tol,l,mid);
        build(tor,mid+1,r);
    }
    void change(int id,int l,int r,int val,int pos){
        if(l<=t[id].l and t[id].r<=r){
            if(t[id].pos==0 or t[id].minn>=val){
                t[id].pos=pos;
                t[id].minn=val;
            }
            return;
        }
        if(r<=t[tol].r) change(tol,l,r,val,pos);
        else if(l>=t[tor].l) change(tor,l,r,val,pos);
        else{
            change(tol,l,t[tol].r,val,pos);
            change(tor,t[tor].l,r,val,pos);
        }
    }
    pair<int,int> ask(int id,int pos){
        if(t[id].l==t[id].r){
            return {t[id].minn,t[id].pos};
        }
        pair<int,int> res={};
        if(pos<=t[tol].r) res=ask(tol,pos);
        else res=ask(tor,pos);
        if(t[id].pos==0) return res;
        if(res.second==0 or t[id].minn<res.first) return {t[id].minn,t[id].pos};
        else if(t[id].minn==res.first and t[id].pos>res.second) return {t[id].minn,t[id].pos};
        return res;
    }
};
stree x,y;
int cal(int x,int y,int id,int xans,int yans){
    if(x==0) return y;
    if(y==0) return x;
    if(q[id].a==0){
        if(q[x].c<q[y].c) return x;
        return y;
    }
    if(q[id].b==0){
        if(q[x].a<q[y].a) return x;
        return y;
    }
    if(xans*q[id].a==yans*q[id].b){
        if(x>y) return x;
        return y;
    }
    if(xans*q[id].a<yans*q[id].b){
        return x;
    }
    return y;
}
signed main(){
    // freopen("down/T2/ex_raytracing.in","r",stdin);
    // freopen("out.out","w",stdout);
    freopen("raytracing.in","r",stdin);
    freopen("raytracing.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld",&q[i].op);
        if(q[i].op==1){
            scanf("%lld %lld %lld %lld",&q[i].a,&q[i].b,&q[i].c,&q[i].d);
            if(q[i].c) a[++cnt]=hdk::frac(q[i].b,q[i].c);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].d,q[i].a);
        }
        else{
            scanf("%lld %lld",&q[i].a,&q[i].b);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
        }
    }
    sort(a+1,a+cnt+1,cmp);
    // cout<<"cth "<<endl;
    for(int i=1;i<=cnt;++i){
        if(i==1 or !(a[i]==a[i-1])){
            mp[a[i]]=++ree;
        }
    }
    x.build(1,1,ree);//cout<<"cth "<<endl;
    y.build(1,1,ree);//cout<<"cth "<<endl;
    for(int i=1;i<=n;++i){
        if(q[i].op==1){
            int r1=maped({q[i].b,q[i].c});
            int r2=maped({q[i].d,q[i].a});
            int mid=maped({q[i].b,q[i].a});
            // cout<<"x change "<<min(r1,mid)<<" "<<max(r1,mid)<<": val="<<q[i].b<<" pos="<<i<<endl;
            x.change(1,min(r1,mid),max(r1,mid),q[i].b,i);
            // cout<<"y change "<<min(r2,mid)<<" "<<max(r2,mid)<<": val="<<q[i].a<<" pos="<<i<<endl;
            y.change(1,min(r2,mid),max(r2,mid),q[i].a,i);
        }
        else{
            pair<int,int> tmp1=x.ask(1,maped({q[i].b,q[i].a}));
            // cout<<"x ask "<<maped({q[i].b,q[i].a})<<" :"<<"val= "<<tmp1.first<<" pos="<<tmp1.second<<endl;
            pair<int,int> tmp2=y.ask(1,maped({q[i].b,q[i].a}));
            // cout<<"y ask "<<maped({q[i].b,q[i].a})<<" :"<<"val= "<<tmp2.first<<" pos="<<tmp2.second<<endl;
            cout<<cal(tmp1.second,tmp2.second,i,tmp1.first,tmp2.first)<<'\n';
        }
    }
}

10.06 21:19 30pts

#include<bits/stdc++.h>
#define int long long
#ifndef FRAC_H
#define FRAC_H
using namespace std;
namespace hdk{
class frac{
    public:
        int z,m;
        frac(int x=0,int y=1){
            z=x,m=y;
            fixed();
        }
        frac fixed(){
            int gcd=__gcd(abs(z),abs(m));
            if(m<0){
                m*=-1;z*=-1;
            }
            if(z==0){
                m=1;return *this;
            }
            if(gcd==0) return *this;
            z/=gcd;m/=gcd;
            return *this;
        }
        frac upside(){
            return frac(m,z);
        }
        frac operator = (pair<int,int>A){
            z=A.first;m=A.second;fixed();
            return *this;
        }
        frac operator + (frac A){
            return (frac(z*A.m+m*A.z,m*A.m)).fixed();
        }
        frac operator * (frac A){
            return (frac(z*A.z,m*A.m)).fixed();
        }
        frac operator / (frac A){
            return (*this*A.upside()).fixed();
        }
        frac operator -(){
            return frac(-z,m);
        }
        frac operator -(frac A){
            return *this+(-A);
        }
        bool operator <(const frac &A)const{
            return z*A.m<A.z*m;
        }
        bool operator ==(const frac &A)const{
            return z*A.m==A.z*m;
        }
        bool operator >(const frac &A)const{
            return !(*this==A and *this<A);
        }
};
}
#endif
using namespace std;
int n;
struct ques{
    int op;
    int a,b,c,d;
}q[100001];
hdk::frac a[400001];
int cnt,ree=1;
map<hdk::frac,int>mp;
bool cmp(const hdk::frac &A,const hdk::frac &B){
    return B<A;
}
inline int maped(pair<int,int> x){
    if(x.second==0) return 1;
    return mp[hdk::frac(x.first,x.second)];
}
struct stree{
    struct tree{
        int l,r;
        int pos,minn;
    }t[1000001];
    #define tol (id*2)
    #define tor (id*2+1)
    #define mid(l,r) mid=((l)+(r))/2
    void build(int id,int l,int r){
        t[id].l=l;t[id].r=r;
        t[id].pos=0;t[id].minn=0;
        if(l==r) return;
        int mid(l,r);
        build(tol,l,mid);
        build(tor,mid+1,r);
    }
    void change(int id,int l,int r,int val,int pos){
        if(l<=t[id].l and t[id].r<=r){
            if(t[id].pos==0 or t[id].minn>=val){
                t[id].pos=pos;
                t[id].minn=val;
            }
            return;
        }
        if(r<=t[tol].r) change(tol,l,r,val,pos);
        else if(l>=t[tor].l) change(tor,l,r,val,pos);
        else{
            change(tol,l,t[tol].r,val,pos);
            change(tor,t[tor].l,r,val,pos);
        }
    }
    pair<int,int> ask(int id,int pos){
        if(t[id].l==t[id].r){
            return {t[id].minn,t[id].pos};
        }
        pair<int,int> res={};
        if(pos<=t[tol].r) res=ask(tol,pos);
        else res=ask(tor,pos);
        if(t[id].pos==0) return res;
        if(res.second==0 or t[id].minn<res.first) return {t[id].minn,t[id].pos};
        else if(t[id].minn==res.second and t[id].pos>res.first) return {t[id].minn,t[id].pos};
        return res;
    }
};
stree x,y;
int cal(int x,int y,int id,int xans,int yans){
    if(x==0) return y;
    if(y==0) return x;
    if(q[id].a==0){
        if(q[x].c<q[y].c) return x;
        return y;
    }
    if(q[id].b==0){
        if(q[x].a<q[y].a) return x;
        return y;
    }
    if(xans*q[id].a==yans*q[id].b){
        if(x>y) return x;
        return y;
    }
    if(xans*q[id].a<yans*q[id].b){
        return x;
    }
    return y;
}
signed main(){
    // freopen("down/T2/ex_raytracing.in","r",stdin);
    // freopen("out.out","w",stdout);
    freopen("raytracing.in","r",stdin);
    freopen("raytracing.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld",&q[i].op);
        if(q[i].op==1){
            scanf("%lld %lld %lld %lld",&q[i].a,&q[i].b,&q[i].c,&q[i].d);
            if(q[i].c) a[++cnt]=hdk::frac(q[i].b,q[i].c);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].d,q[i].a);
        }
        else{
            scanf("%lld %lld",&q[i].a,&q[i].b);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
        }
    }
    sort(a+1,a+cnt+1,cmp);
    // cout<<"cth "<<endl;
    for(int i=1;i<=cnt;++i){
        if(i==1 or !(a[i]==a[i-1])){
            mp[a[i]]=++ree;
        }
    }
    x.build(1,1,ree);//cout<<"cth "<<endl;
    y.build(1,1,ree);//cout<<"cth "<<endl;
    for(int i=1;i<=n;++i){
        if(q[i].op==1){
            int r1=maped({q[i].b,q[i].c});
            int r2=maped({q[i].d,q[i].a});
            int mid=maped({q[i].b,q[i].a});
            // cout<<"x change "<<min(r1,mid)<<" "<<max(r1,mid)<<": val="<<q[i].b<<" pos="<<i<<endl;
            x.change(1,min(r1,mid),max(r1,mid),q[i].b,i);
            // cout<<"y change "<<min(r2,mid)<<" "<<max(r2,mid)<<": val="<<q[i].a<<" pos="<<i<<endl;
            y.change(1,min(r2,mid),max(r2,mid),q[i].a,i);
        }
        else{
            pair<int,int> tmp1=x.ask(1,maped({q[i].b,q[i].a}));
            // cout<<"x ask "<<maped({q[i].b,q[i].a})<<" :"<<"val= "<<tmp1.first<<" pos="<<tmp1.second<<endl;
            pair<int,int> tmp2=y.ask(1,maped({q[i].b,q[i].a}));
            // cout<<"y ask "<<maped({q[i].b,q[i].a})<<" :"<<"val= "<<tmp2.first<<" pos="<<tmp2.second<<endl;
            cout<<cal(tmp1.second,tmp2.second,i,tmp1.first,tmp2.first)<<'\n';
        }
    }
}

10.06 20:50 0pts

#include<bits/stdc++.h>
#define int long long
#ifndef FRAC_H
#define FRAC_H
using namespace std;
namespace hdk{
class frac{
    public:
        int z,m;
        frac(int x=0,int y=1){
            z=x,m=y;
            fixed();
        }
        frac fixed(){
            int gcd=__gcd(abs(z),abs(m));
            if(m<0){
                m*=-1;z*=-1;
            }
            if(z==0){
                m=1;return *this;
            }
            if(gcd==0) return *this;
            z/=gcd;m/=gcd;
            return *this;
        }
        frac upside(){
            return frac(m,z);
        }
        frac operator = (pair<int,int>A){
            z=A.first;m=A.second;fixed();
            return *this;
        }
        frac operator + (frac A){
            return (frac(z*A.m+m*A.z,m*A.m)).fixed();
        }
        frac operator * (frac A){
            return (frac(z*A.z,m*A.m)).fixed();
        }
        frac operator / (frac A){
            return (*this*A.upside()).fixed();
        }
        frac operator -(){
            return frac(-z,m);
        }
        frac operator -(frac A){
            return *this+(-A);
        }
        bool operator <(const frac &A)const{
            return z*A.m<A.z*m;
        }
        bool operator ==(const frac &A)const{
            return z*A.m==A.z*m;
        }
        bool operator >(const frac &A)const{
            return !(*this==A and *this<A);
        }
};
}
#endif
using namespace std;
int n;
struct ques{
    int op;
    int a,b,c,d;
}q[100001];
hdk::frac a[400001];
int cnt,ree=1;
map<hdk::frac,int>mp;
bool cmp(const hdk::frac &A,const hdk::frac &B){
    return B<A;
}
inline int maped(pair<int,int> x){
    if(x.second==0) return 1;
    return mp[hdk::frac(x.first,x.second)];
}
struct stree{
    struct tree{
        int l,r;
        int pos,minn;
    }t[1000001];
    #define tol (id*2)
    #define tor (id*2+1)
    #define mid(l,r) mid=((l)+(r))/2
    void build(int id,int l,int r){
        t[id].l=l;t[id].r=r;
        t[id].pos=0;t[id].minn=INT_MAX;
        if(l==r) return;
        int mid(l,r);
        build(tol,l,mid);
        build(tor,mid+1,r);
    }
    void change(int id,int l,int r,int val,int pos){
        if(l<=t[id].l and t[id].r<=r){
            if(t[id].pos==0 or t[id].minn>=val){
                t[id].pos=pos;
                t[id].minn=val;
            }
            return;
        }
        if(r<=t[tol].r) change(tol,l,r,val,pos);
        else if(l>=t[tor].l) change(tor,l,r,val,pos);
        else{
            change(tol,l,t[tol].r,val,pos);
            change(tor,t[tor].l,r,val,pos);
        }
    }
    pair<int,int> ask(int id,int pos){
        if(t[id].l==t[id].r){
            return {t[id].minn,t[id].pos};
        }
        pair<int,int> res={};
        if(pos<=t[tol].r) res=ask(tol,pos);
        else res=ask(tor,pos);
        if(t[id].pos==0) return res;
        if(res.second==0 or t[id].minn<res.second) return {t[id].minn,t[id].pos};
        else if(t[id].minn==res.second and t[id].pos>res.first) return {t[id].minn,t[id].pos};
        return res;
    }
};
stree x,y;
int cal(int x,int y,int id,int xans,int yans){
    if(x==0) return y;
    if(y==0) return x;
    if(q[id].a==0){
        if(q[x].c<q[y].c) return x;
        return y;
    }
    if(q[id].b==0){
        if(q[x].a<q[y].a) return x;
        return y;
    }
    if(xans*q[id].a==yans*q[id].b){
        if(x>y) return x;
        return y;
    }
    if(xans*q[id].a<yans*q[id].b){
        return x;
    }
    return y;
}
signed main(){
    // freopen("down/T2/ex_raytracing.in","r",stdin);
    // freopen("out.out","w",stdout);
    // freopen("raytracing.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld",&q[i].op);
        if(q[i].op==1){
            scanf("%lld %lld %lld %lld",&q[i].a,&q[i].b,&q[i].c,&q[i].d);
            if(q[i].c) a[++cnt]=hdk::frac(q[i].b,q[i].c);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].d,q[i].a);
        }
        else{
            scanf("%lld %lld",&q[i].a,&q[i].b);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
        }
    }
    sort(a+1,a+cnt+1,cmp);
    // cout<<"cth "<<endl;
    for(int i=1;i<=cnt;++i){
        if(i==1 or !(a[i]==a[i-1])){
            mp[a[i]]=++ree;
        }
    }
    x.build(1,1,ree);//cout<<"cth "<<endl;
    y.build(1,1,ree);//cout<<"cth "<<endl;
    for(int i=1;i<=n;++i){
        if(q[i].op==1){
            int r1=maped({q[i].b,q[i].c});
            int r2=maped({q[i].d,q[i].a});
            int mid=maped({q[i].b,q[i].a});
            x.change(1,min(r1,mid),max(r1,mid),q[i].b,i);
            y.change(1,min(r2,mid),max(r2,mid),q[i].a,i);
        }
        else{
            pair<int,int> tmp1=x.ask(1,maped({q[i].b,q[i].a}));
            pair<int,int> tmp2=y.ask(1,maped({q[i].b,q[i].a}));
            cout<<cal(tmp1.second,tmp2.second,i,tmp1.first,tmp2.first)<<'\n';
        }
    }
}

10.06 19:35 0pts

#include<bits/stdc++.h>
#define int long long
#ifndef FRAC_H
#define FRAC_H
using namespace std;
namespace hdk{
class frac{
    public:
        int z,m;
        frac(int x=0,int y=1){
            z=x,m=y;
            fixed();
        }
        frac fixed(){
            int gcd=__gcd(abs(z),abs(m));
            if(m<0){
                m*=-1;z*=-1;
            }
            if(z==0){
                m=1;return *this;
            }
            if(gcd==0) return *this;
            z/=gcd;m/=gcd;
            return *this;
        }
        frac upside(){
            return frac(m,z);
        }
        frac operator = (pair<int,int>A){
            z=A.first;m=A.second;fixed();
            return *this;
        }
        frac operator + (frac A){
            return (frac(z*A.m+m*A.z,m*A.m)).fixed();
        }
        frac operator * (frac A){
            return (frac(z*A.z,m*A.m)).fixed();
        }
        frac operator / (frac A){
            return (*this*A.upside()).fixed();
        }
        frac operator -(){
            return frac(-z,m);
        }
        frac operator -(frac A){
            return *this+(-A);
        }
        bool operator <(const frac &A)const{
            return z*A.m<A.z*m;
        }
        bool operator ==(const frac &A)const{
            return z*A.m==A.z*m;
        }
        bool operator >(const frac &A)const{
            return !(*this==A and *this<A);
        }
        void print(){
            fixed();
            cout<<z<<"/"<<m;
        }
};
}
#endif
using namespace std;
int n;
struct ques{
    int op;
    int a,b,c,d;
}q[100001];
hdk::frac a[200001];
int cnt;
map<hdk::frac,int>mp;
inline int maped(pair<int,int> x){
    if(x.second==0) return cnt+1;
    return mp[hdk::frac(x.first,x.second)];
}
struct stree{
    struct tree{
        int l,r;
        int pos,minn;
    }t[800001];
    #define tol (id*2)
    #define tor (id*2+1)
    #define mid(l,r) mid=((l)+(r))/2
    void build(int id,int l,int r){
        t[id].l=l;t[id].r=r;
        t[id].pos=0;t[id].minn=LLONG_MAX;
        if(l==r) return;
        int mid(l,r);
        build(tol,l,mid);
        build(tor,mid+1,r);
    }
    void change(int id,int l,int r,int val,int pos){
        if(l<=t[id].l and t[id].r<=r){
            if(t[id].pos==0 or t[id].minn>=val){
                t[id].pos=pos;
                t[id].minn=val;
            }
            return;
        }
        if(r<=t[tol].r) change(tol,l,r,val,pos);
        else if(l>=t[tor].l) change(tor,l,r,val,pos);
        else{
            change(tol,l,t[tol].r,val,pos);
            change(tor,t[tor].l,r,val,pos);
        }
    }
    pair<int,int> ask(int id,int pos){
        if(t[id].l==t[id].r){
            return {t[id].minn,t[id].pos};
        }
        pair<int,int> res={};
        if(pos<=t[tol].r) res=ask(tol,pos);
        else res=ask(tor,pos);
        if(t[id].pos==0) return res;
        if(res.second==0 or t[id].minn<res.second) return {t[id].minn,t[id].pos};
        else if(t[id].minn==res.second and t[id].pos>res.first) return {t[id].minn,t[id].pos};
        return res;
    }
};
stree x,y;
int cal(int x,int y,int id,int xans,int yans){
    if(x==0) return y;
    if(y==0) return x;
    if(q[id].a==0){
        if(q[x].c<q[y].c) return x;
        return y;
    }
    if(q[id].b==0){
        if(q[x].a<q[y].a) return x;
        return y;
    }
    if(xans*q[id].a==yans*q[id].b){
        if(x>y) return x;
        return y;
    }
    if(xans*q[id].a<yans*q[id].b){
        return x;
    }
    return y;
}
signed main(){
    freopen64("raytracing.in","r",stdin);
    freopen64("raytracing.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld",&q[i].op);
        if(q[i].op==1){
            scanf("%lld %lld %lld %lld",&q[i].a,&q[i].b,&q[i].c,&q[i].d);
            if(q[i].c) a[++cnt]=hdk::frac(q[i].b,q[i].c);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].d,q[i].a);
        }
        else{
            scanf("%lld %lld",&q[i].a,&q[i].b);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
        }
    }
    sort(a+1,a+cnt+1);
    for(int i=1;i<=cnt;++i){
        mp[a[i]]=i;
            // cout<<i<<":";a[i].print();cout<<" "<<a[i].z*1.0/a[i].m<<endl;
    }
    x.build(1,1,cnt+1);
    y.build(1,1,cnt+1);
    for(int i=1;i<=n;++i){
        // cout<<"ques "<<i<<endl;
        if(q[i].op==1){
            int r1=maped({q[i].b,q[i].c});
            int r2=maped({q[i].d,q[i].a});
            int mid=maped({q[i].b,q[i].a});
            x.change(1,min(r1,mid),max(r1,mid),q[i].b,i);
            y.change(1,min(r2,mid),max(r2,mid),q[i].a,i);
        }
        else{
            pair<int,int> tmp1=x.ask(1,maped({q[i].b,q[i].a}));
            pair<int,int> tmp2=y.ask(1,maped({q[i].b,q[i].a}));
            cout<<cal(tmp1.second,tmp2.second,i,tmp1.first,tmp2.first)<<endl;
            // cout<<(tmp==-1?0:tmp)<<'\n';
        }
    }
}

10.06 18:20 0pts

#include<bits/stdc++.h>
#define int long long
#ifndef FRAC_H
#define FRAC_H
using namespace std;
namespace hdk{
class frac{
    private:
        int z,m;
    public:
        frac(int x=0,int y=1){
            z=x,m=y;
            fixed();
        }
        frac fixed(){
            int gcd=__gcd(abs(z),abs(m));
            if(m<0){
                m*=-1;z*=-1;
            }
            if(z==0){
                m=1;return *this;
            }
            if(gcd==0) return *this;
            z/=gcd;m/=gcd;
            return *this;
        }
        frac upside(){
            return frac(m,z);
        }
        frac operator = (pair<int,int>A){
            z=A.first;m=A.second;fixed();
            return *this;
        }
        frac operator + (frac A){
            return (frac(z*A.m+m*A.z,m*A.m)).fixed();
        }
        frac operator * (frac A){
            return (frac(z*A.z,m*A.m)).fixed();
        }
        frac operator / (frac A){
            return (*this*A.upside()).fixed();
        }
        frac operator -(){
            return frac(-z,m);
        }
        frac operator -(frac A){
            return *this+(-A);
        }
        bool operator <(const frac &A)const{
            return z*A.m<A.z*m;
        }
        bool operator ==(const frac &A)const{
            return z*A.m==A.z*m;
        }
        bool operator >(const frac &A)const{
            return !(*this==A and *this<A);
        }
        void print(){
            fixed();
            cout<<z<<"/"<<m<<endl;
        }
};
}
#endif
using namespace std;
int n;
struct ques{
    int op;
    int a,b,c,d;
}q[100001];
hdk::frac a[200001];
int cnt;
map<hdk::frac,int>mp;
inline int maped(pair<int,int> x){
    if(x.second==0) return cnt+1;
    return mp[hdk::frac(x.first,x.second)];
}
namespace stree{
    struct tree{
        int l,r;
        int pos;
        int lazy;
    }t[800001];
    #define tol (id*2)
    #define tor (id*2+1)
    #define mid(l,r) mid=((l)+(r))/2
    void build(int id,int l,int r){
        t[id].l=l;t[id].r=r;
        t[id].pos=-1;
        if(l==r) return;
        int mid(l,r);
        build(tol,l,mid);
        build(tor,mid+1,r);
    }
    void pushdown(int id){
        if(t[id].lazy){
            t[tol].pos=t[id].lazy;
            t[tol].lazy=t[id].lazy;
            t[tor].pos=t[id].lazy;
            t[tor].lazy=t[id].lazy;
            t[id].lazy=0;
        }
    }
    void change(int id,int l,int r,int val){
        if(l<=t[id].l and t[id].r<=r){
            t[id].pos=val;
            t[id].lazy=val;
            return;
        }
        pushdown(id);
        if(r<=t[tol].r) change(tol,l,r,val);
        else if(l>=t[tor].l) change(tor,l,r,val);
        else{
            change(tol,l,t[tol].r,val);
            change(tor,t[tor].l,r,val);
        }
    }
    int ask(int id,int pos){
        if(t[id].l==t[id].r){
            return t[id].pos;
        }
        pushdown(id);
        if(pos<=t[tol].r) return ask(tol,pos);
        return ask(tor,pos);
    }
}
signed main(){
    freopen("raytracing.in","r",stdin);
    freopen("raytracing.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;++i){
        scanf("%lld",&q[i].op);
        if(q[i].op==1){
            scanf("%lld %lld %lld %lld",&q[i].a,&q[i].b,&q[i].c,&q[i].d);
            if(q[i].c) a[++cnt]=hdk::frac(q[i].b,q[i].c);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].d,q[i].a);
        }
        else{
            scanf("%lld %lld",&q[i].a,&q[i].b);
            if(q[i].a) a[++cnt]=hdk::frac(q[i].b,q[i].a);
        }
    }
    sort(a+1,a+cnt+1);
    cnt=unique(a+1,a+n+1)-a;
    for(int i=1;i<=cnt;++i){
        mp[a[i]]=i;
    }
    stree::build(1,1,cnt+1);
    for(int i=1;i<=n;++i){
        // cout<<"ques "<<i<<endl;
        if(q[i].op==1){
            int r1=maped({q[i].b,q[i].c});
            int r2=maped({q[i].d,q[i].a});
            stree::change(1,min(r1,r2),max(r1,r2),i);
        }
        else{
            int tmp=stree::ask(1,maped({q[i].b,q[i].a}));
            cout<<(tmp==-1?-1:tmp)<<'\n';
        }
    }
}
posted @ 2024-10-06 20:50  HaneDaniko  阅读(41)  评论(1编辑  收藏  举报