QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317449#7803. H-Shaped Figureslmf_upRE 151ms3996kbC++2020.1kb2024-01-29 00:52:502024-01-29 00:52:51

Judging History

你现在查看的是最新测评结果

  • [2024-01-29 00:52:51]
  • 评测
  • 测评结果:RE
  • 用时:151ms
  • 内存:3996kb
  • [2024-01-29 00:52:50]
  • 提交

answer

#include<bits/stdc++.h>

#define cp const point &
#define cl const line &
#define cc const circle &
#define LD long double
std::mt19937 rnd(time(0));
const LD eps = 1e-8;
const LD pi = std::numbers::pi;
const LD INF = 1e9;

int sgn(LD x)
{
    return x > eps ? 1 : (x < -eps ? -1 : 0);
}

LD sqr(LD x)
{ return x * x; }

struct point
{
    LD x, y;

    point operator+(cp a) const
    { return {x + a.x, y + a.y}; }

    point operator-(cp a) const
    { return {x - a.x, y - a.y}; }

    point operator*(LD t) const
    { return {x * t, y * t}; }

    point operator/(LD t) const
    { return {x / t, y / t}; }

    point rot(LD t) const
    { return {x * cos(t) - y * sin(t), x * sin(t) + y * cos(t)}; }

    point rot90() const
    { return {-y, x}; }

    LD len2() const
    { return x * x + y * y; }

    LD len() const
    { return sqrtl(x * x + y * y); }

    point unit() const
    {
        double d = len();
        return {x / d, y / d};
    }
    void print()
    {
        std::cout<<x<<' '<<y<<std::endl;
    }
    friend bool operator<(cp a, cp b)
    {
        return a.x == b.x ? a.y < b.y : a.x < b.x;
    }

    friend bool operator>(cp a, cp b)
    {
        return a.x == b.x ? a.y > b.y : a.x > b.x;
    }
};

LD dot(cp a, cp b);

bool operator==(cp a, cp b)
{
    return !sgn(dot(a - b, a - b));
}

LD dis(cp a, cp b)//两点距离
{
    return sqrtl(sqr(a.x - b.x) + sqr(a.y - b.y));
}

LD dot(cp a, cp b)//点乘
{
    return a.x * b.x + a.y * b.y;
}

LD det(cp a, cp b)//叉乘
{
    return a.x * b.y - b.x * a.y;
}

bool turn_left(cp a, cp b, cp c)//判断ba是否逆时针转少于180°到ca
{
    return sgn(det(b - a, c - a)) > 0;//大于是严格凸包
}

struct line
{
    point s, t;
    line() {}
    line(point a, point b) : s(a), t(b)
    {}
};

struct circle
{
    point c;
    LD r;

    circle()
    {}

    circle(point C, LD R)
    { c = C, r = R; }
};

bool in_circle(cp a, cc b)
{
    return sgn((b.c - a).len() - b.r) <= 0;
}

circle make_circle(point u, point v)
{
    point p = (u + v) / 2;
    return circle(p, (u - p).len());
}

circle make_circle(cp a, cp b, cp c)
{
    point p = b - a, q = c - a;
    point s(dot(p, p) / 2, dot(q, q) / 2);
    LD d = det(p, q);
    p = point(det(s, point(p.y, q.y)), det(point(p.x, q.x), s)) / d;
    return circle(a + p, p.len());
}

circle min_circle(std::vector<point> p)
{
    circle ret(p[0], 0);
    std::shuffle(p.begin(), p.end(), rnd);
    int len = p.size();
    for (int i = 0; i < len; i++)
        if (!in_circle(p[i], ret))
        {
            ret = circle(p[i], 0);
            for (int j = 0; j < i; j++)
                if (!in_circle(p[j], ret))
                {
                    ret = make_circle(p[j], p[i]);
                    for (int k = 0; k < j; ++k)
                        if (!in_circle(p[k], ret))
                            ret = make_circle(p[i], p[j], p[k]);
                }
        }
    return ret;
}


bool same_dir(cl a, cl b)//判断方向是否一致
{
    return sgn(det(b.t - b.s, a.t - a.s)) == 0 && sgn(dot(b.t - b.s, a.t - a.s)) > 0;
}

bool point_on_line(cp a, cl l)//判断点是否在直线上
{
    return sgn(det(a-l.s, l.t - l.s)) == 0;
}

bool point_on_segment(cp a, cl l)//判断点是否在线段上
{
    return point_on_line(a, l) && sgn(dot(l.s - a, l.t-a )) < 0;//(<=代表可以端点
}

bool two_side(cp a, cp b, cl c)//判断两个点是否在线段的两边
{
    return sgn(det(a - c.s, c.t - c.s)) * sgn(det(b - c.s, c.t - c.s)) < 0;
}

bool intersect_judge(cl a, cl b)
{//判断两个线段是否相交
    if (point_on_segment(a.s, b) || point_on_segment(a.t, b) || point_on_segment(b.s, a) ||
        point_on_segment(b.t, a))
        return true;
    return two_side(a.s, a.t, b) && two_side(b.s, b.t, a);
}

point line_intersect(cl a, cl b)
{//得到两线段的交点
    double s1 = det(a.t - a.s, b.s - a.s);
    double s2 = det(a.t - a.s, b.t - a.s);
    return (b.s * s2 - b.t * s1) / (s2 - s1);
}

bool point_on_ray(cp a, cl b)
{//判断点是否在射线上
    return sgn(det(a - b.s, b.t - b.s)) == 0 && sgn(dot(a - b.s, b.t - b.s)) >= 0;
}

bool ray_intersect_judge(line a, line b)//判断两射线是否相交
{
    double s1, s2;
    s1 = det(a.t - a.s, b.s - a.s);
    s2 = det(a.t - a.s, b.t - a.s);
    if (sgn(s1) == 0 && sgn(s2) == 0)
        return sgn(dot(a.t - a.s, b.s - a.s)) >= 0 || sgn(dot(b.t - b.s, a.s - b.s));
    if (!sgn(s1 - s2) || sgn(s1) == sgn(s2 - s1))return 0;
    std::swap(a, b);
    s1 = det(a.t - a.s, b.s - a.s);
    s2 = det(a.t - a.s, b.t - a.s);
    return sgn(s1) != sgn(s2 - s1);
}

LD point_to_line(cp a, cl b)
{//点到直线的距离
    return abs(det(b.t - b.s, a - b.s)) / dis(b.s, b.t);
}

point project_to_line(cp a, cl b)
{//得到点在线上的投影
    return b.s + (b.t - b.s) * (dot(a - b.s, b.t - b.s) / (b.t - b.s).len2());
}

LD point_to_segment(cp a, cl b)
{//点到线段的距离
    if (b.s == b.t)
        return dis(a, b.s);
    if (sgn(dot(b.s - a, b.t - b.s)) * sgn(dot(b.t - a, b.t - b.s)) <= 0)
        return abs(det(b.t - b.s, a - b.s)) / dis(b.s, b.t);
    return std::min(dis(a, b.s), dis(a, b.t));
}
std::vector<point>line_circle_intersect(cl a,cc b)
{//返回线与圆的交点
    if(sgn(point_to_segment(b.c,a)-b.r)>0)
        return std::vector<point>();
    LD x=sqrtl(sqr(b.r)- sqr(point_to_line(b.c,a)));
    return std::vector<point>({project_to_line(b.c,a)+(a.s-a.t).unit()*x, project_to_line(b.c,a)-(a.s-a.t).unit()*x});
}
LD circle_intersect_area(cc a,cc b){
    LD d=dis(a.c,b.c);
    if(sgn(d-(a.r+b.r))>=0)return 0;
    if(sgn(d- abs(a.r-b.r))<=0){
        LD r=std::min(a.r,b.r);
        return r*r*pi;
    }
    LD x=(d*d+a.r*a.r-b.r*b.r)/(2*d),
    t1=acosl(std::min((LD)1,std::max((LD)-1,x/a.r))),
    t2=acosl(std::min((LD)1,std::max((LD)-1,(d-x)/b.r)));
    return sqr(a.r)*t1+ sqr(b.r)*t2-d*a.r*sinl(t1);
}
std::vector<point> circle_intersect(cc a,cc b)
{
    if(a.c==b.c||sgn(dis(a.c,b.c)-a.r-b.r)>0||sgn(dis(a.c,b.c)-abs(a.r-b.r))<0)
        return {};
    point r=(b.c-a.c).unit();
    LD d=dis(a.c,b.c);
    LD x=((sqr(a.r)-sqr(b.r))/d+d)/2;
    LD h=sqrtl(sqr(a.r)-sqr(x));
    if(sgn(h)==0)return {a.c+r*x};
    return {a.c+r*x+r.rot90()*h,a.c+r*x-r.rot90()*h};
}
std::vector<point>tangent(cp a,cc b)
{
    circle p= make_circle(a,b.c);
     return circle_intersect(p,b);
}
std::vector<line>extangent(cc a,cc b)
{
    std::vector<line>ret;
    if(sgn(dis(a.c,b.c)-abs(a.r-b.r))<=0)return ret;
    if(sgn(a.r-b.r)==0)
    {
        point dir=b.c-a.c;
        dir=(dir*a.r/dir.len()).rot90();
        ret.push_back(line(a.c+dir,b.c+dir));
        ret.push_back(line(a.c-dir,b.c-dir));
    }
    else{
        point p=(b.c*a.r-a.c*b.r)/(a.r-b.r);
        std::vector pp= tangent(p,a),qq= tangent(p,b);
        if(pp.size()==2&&qq.size()==2)
        {
            if(sgn(a.r-b.r)<0)
                std::swap(pp[0],pp[1]),std::swap(qq[0],qq[1]);
            ret.push_back(line(pp[0],qq[0]));
            ret.push_back(line(pp[1],qq[1]));
        }
    }
    return ret;
}
std::vector<line>intangeent(cc a,cc b)
{
    std::vector<line> ret;
    point p=(b.c*a.r+a.c*b.r)/(a.r+b.r);
    std::vector pp= tangent(p,a),qq= tangent(p,b);
    if(pp.size()==2&&qq.size()==2){
        ret.push_back(line(pp[0],qq[0]));
        ret.push_back(line(pp[1],qq[1]));
    }
    return ret;
}
std::vector<point>cut(const std::vector<point>&c,line p){
    std::vector<point>ret;
    if(c.empty())return ret;
    int len=c.size();
    for(int i=0;i<len;i++)
    {
        int j=(i+1)%len;
        if(turn_left(p.s,p.t,c[i]))ret.push_back(c[i]);
        if(two_side(c[i],c[j],p))
            ret.push_back(line_intersect(p,line(c[i],c[j])));
    }
    return ret;
}
std::vector<point> convex_hull(std::vector<point> a)
{//凸包,字典序
    int n = (int) a.size(), cnt = 0;
    if (n < 2) return a;
    std::sort(a.begin(), a.end()); // less<pair>
    std::vector<point> ret;
    for (int i = 0; i < n; ++i)
    {
        while (cnt > 1
               && !turn_left(ret[cnt - 1], a[i], ret[cnt - 2]))
            --cnt, ret.pop_back();
        ++cnt, ret.push_back(a[i]);
    }
    int fixed = cnt;
    for (int i = n - 2; i >= 0; --i)
    {
        while (cnt > fixed
               && !turn_left(ret[cnt - 1], a[i], ret[cnt - 2]))
            --cnt, ret.pop_back();
        ++cnt, ret.push_back(a[i]);
    }
    ret.pop_back();
    return ret;
}

std::vector<point> minkovski(std::vector<std::vector<point>> a)
{
    if (a[0].size() == 1)
        return a[1];
    if (a[1].size() == 1)
        return a[0];
    for (int i = 0; i < 2; i++)a[i].push_back(a[i].front());
    int i[2] = {0, 0}, len[2] = {(int) a[0].size() - 1, (int) a[1].size() - 1};
    std::vector<point> ret;
    ret.push_back(a[0][0] + a[1][0]);
    do
    {
        int d = sgn(det(a[1][i[1] + 1] - a[1][i[1]], a[0][i[0] + 1] - a[0][i[0]])) >= 0;
        ret.push_back(a[d][i[d] + 1] - a[d][i[d]] + ret.back());
        i[d] = (i[d] + 1) % len[d];
    }
    while (i[0] || i[1]);
    return ret;
}

struct Convex
{
    int n;
    std::vector<point> a, upper, lower;

    Convex(std::vector<point> _a) : a(_a)
    {
        n = a.size();
        int k = 0;
        for (int i = 1; i < n; i++)if (a[k] < a[i])k = i;
        for (int i = 0; i <= k; i++) lower.push_back(a[i]);
        for (int i = k; i < n; i++) upper.push_back(a[i]);
        upper.push_back(a[0]);
    }

    std::pair<LD, int> get_tan(std::vector<point> &con, point vec)
    {
        int l = 0, r = (int) con.size() - 2;
        for (; l + 1 < r;)
        {
            int mid = (l + r) / 2;
            if (sgn(det(con[mid + 1] - con[mid], vec)) > 0)r = mid;
            else l = mid;
        }
        return std::max(std::make_pair(det(vec, con[r]), r), std::make_pair(det(vec, con[0]), 0));
    }

    void upd_tan(cp p, int id, int &i0, int &i1)
    {
        if (sgn(det(a[i0] - p, a[id] - p)) > 0) i0 = id;
        if (sgn(det(a[i1] - p, a[id] - p)) < 0) i1 = id;
    }

    void search(int l, int r, point p, int &i0, int &i1)
    {
        if (l == r)return;
        upd_tan(p, l % n, i0, i1);
        int sl = sgn(det(a[l % n] - p, a[(l + 1) % n] - p));
        for (; l + 1 < r;)
        {
            int mid = (l + r) / 2;
            int smid = sgn(det(a[mid % n] - p, a[(mid + 1) % n] - p));
            if (smid == sl)l = mid;
            else r = mid;
        }
        upd_tan(p, r % n, i0, i1);
    }

    int search(point u, point v, int l, int r)
    {
        int sl = sgn(det(v - u, a[l % n] - u));
        for (; l + 1 < r;)
        {
            int mid = (l + r) / 2;
            int smid = sgn(det(v - u, a[mid % n] - u));
            if (smid == sl) l = mid;
            else r = mid;
        }
        return l % n;
    }

    //判定点是否在凸包内,在边界返回true
    bool contain(point p)
    {
        if (p.x < lower[0].x || p.x > lower.back().x)return false;
        int id = std::lower_bound(lower.begin(), lower.end(), point(p.x, -INF)) - lower.begin();
        if (lower[id].x == p.x)
        {
            if (lower[id].y > p.y)return false;
        }
        else if (det(lower[id - 1] - p, lower[id] - p) < 0)
            return false;
        id = std::lower_bound(upper.begin(), upper.end(), point(p.x, INF), std::greater<point>()) - upper.begin();
        if (upper[id].x == p.x)
        {
            if (upper[id].y < p.y)return false;
        }
        else if (det(upper[id - 1] - p, upper[id] - p) < 0)
            return false;
        return true;
    }
    bool get_tan(point p,int &i0,int &i1){// 求点 p 关于凸包的两个切点, 如果在凸包外则有序返回编号, 共线的多个切点返回任意一个, 否则返回 false
        i0=i1=0;
        int id=int(std::lower_bound(lower.begin(),lower.end(),p)-lower.begin());
        search(0,id,p,i0,i1);
        search(id,(int)lower.size(),p,i0,i1);
        id=int(std::lower_bound(upper.begin(),upper.end(),p,std::greater<point>())-upper.begin());
        search((int)lower.size()-1,(int)lower.size()-1+id,p,i0,i1);
        search((int)lower.size()-1+id,(int)lower.size()-1+(int)upper.size(),p,i0,i1);
        return true;
    }
    // 求凸包上和向量 vec 叉积最大的点, 返回编号, 共线的多个切点返回任意一个
    int get_tan(point vec)
    {
        std::pair<LD,int>ret= get_tan(upper,vec);
        ret.second=(ret.second+(int)lower.size()-1)%n;
        ret=std::max(ret, get_tan(lower,vec));
        return ret.second;
    }
    // 求凸包和直线 u,v 的交点, 如果无严格相交返回 false. 如果有则是和 (i,next(i)) 的交点, 两个点无序, 交在点上不确定返回前后两条线段其中之一

    bool get_inter(point u,point v,int &i0,int &i1){
        int p0= get_tan(u-v),p1= get_tan(v-u);
        if(sgn(det(v-u,a[p0]-u))*sgn(det(v-u,a[p1]-u))<0)
        {
            if(p0>p1)std::swap(p0,p1);
            i0= search(u,v,p0,p1);
            i1= search(u,v,p1,p0+n);
            return true;
        }
        else return false;
    }
};
bool in_polygon(cp p,const std::vector<point>&po)
{
    int n=(int)po.size();int cnt=0;
    for(int i=0;i<n;i++)
    {
        point a=po[i],b=po[(i+1)%n];
        if(point_on_segment(p,line(a,b)))return true;
        int x=sgn(det(p-a,b-a)),y=sgn(a.y-p.y),z=sgn(b.y-p.y);
        if(x>0&&y<=0&&z>0)++cnt;
        if(x<0&&z<=0&&y>0)--cnt;

    }
    return cnt!=0;
}
bool In_Polygon(cp P,std::vector<point>&polygon)
{
    bool flag = false; //相当于计数
    point P1,P2; //多边形一条边的两个顶点
    int n=polygon.size();
    for(int i=0,j=n-1;i<n;j=i++)
    {
        //polygon[]是给出多边形的顶点
        P1 = polygon[i];
        P2 = polygon[j];
        if(point_on_segment(P,line(P1,P2)))return true;
        //前一个判断min(P1.y,P2.y)<P.y<=max(P1.y,P2.y)
        //这个判断代码我觉得写的很精妙 我网上看的 应该是大神模版
        //后一个判断被测点 在 射线与边交点 的左边
        if( (sgn(P1.y-P.y)>0 != sgn(P2.y-P.y)>0) && sgn(P.x - (P.y-P1.y)*(P1.x-P2.x)/(P1.y-P2.y)-P1.x)<0)
            flag = !flag;
    }
    return flag;
}
std::vector<point> Minkovski(std::vector<std::vector<point>> a)
{                                                            //闵可夫斯基和
    std::vector<point> S;
    int n = a[0].size(), m = a[1].size();
    std::vector<point> A(n ), B(m );
    for (int i = 0; i < n - 1; i++) A[i] = a[0][i + 1] - a[0][i];
    A[n - 1] = a[0][0] - a[0][n - 1];
    for (int i = 0; i < m - 1; i++) B[i] = a[1][i + 1] - a[1][i];
    B[m - 1] = a[1][0] - a[1][m - 1];                                                             //将两个凸包上的边向量都存入a,b中
    S.push_back(a[0][0] + a[1][0]);
    int p1 = 0, p2 = 0;
    while (p1 < n && p2 < m)
    {
        LD d = det(A[p1], B[p2]);
        if (d > 0)
            S.push_back(S.back()+A[p1++]);
        else if (d < 0)
            S.push_back(S.back()+B[p2++]);
        else
        {
            if(dot(A[p1],B[p1])>=0)
                S.push_back(S.back()+A[p1++]);
            else
            {
                auto [x,y]=A[p1];
                if(x>0)
                    S.push_back(S.back()+A[p1++]);
                else if(x<0)
                    S.push_back(S.back()+B[p2++]);
                else
                {
                    if(y>0)
                        S.push_back(S.back()+A[p1++]);
                    else S.push_back(S.back()+B[p2++]);
                }
            }
        }
    }
    while (p1 < n)
        S.push_back(S.back() + A[p1++]);
    while (p2 < m)
        S.push_back(S.back() + B[p2++]);
    return S;
}

void print(std::vector<point> res)
{
    std::cout << "print:\n";
    int cnt=0;
    for (auto [x, y]: res)
        std::cout <<++cnt<<' '<< x << ' ' << y << std::endl;
    std::cout << "end\n";
}
int flag=1;
int T;
struct BIT{
    int n;
    std::vector<int>sum;
    void init(int x)
    {
        sum.resize(x+1,0);
        n=x;
    }
    void add(int x,int y)
    {
        while(x<=n)
            sum[x]+=y,x+=x&-x;
    }
    int get_sum(int x)
    {
        int res=0;
        while(x>0)
            res+=sum[x],x-=x&-x;
        return res;
    }
};
void get_id(point p,std::vector<std::pair<point,std::array<int,3>>>&num,int op)
{
    int n=num.size();
    std::sort(num.begin(),num.end(),[&](auto x,auto y)
    {
        return sgn(det(x.first-p,y.first-p))>0;
    });
    int rk=0;

    for(int i=0;i<n;i++)
    {
        if(!i)
            num[i].second[op]=++rk;
        else
        {
            if(sgn(det(num[i].first-p,num[i-1].first-p))==0)
                num[i].second[op]=rk;
            else num[i].second[op]=++rk;
        }
    }
}
long long solve1(point p,point q,std::vector<line>left,std::vector<line>right)
{
    int len_left=left.size(),len_right=right.size();
    std::vector<std::pair<point,std::array<int,3>>>num;
    for(auto [s,t]:left)
        num.push_back(std::make_pair(s,std::array<int,3>{0,0,0}));
    for(auto [s,t]:right)
        num.push_back(std::make_pair(s,std::array<int,3>{0,0,1}));
    int n=num.size();
    get_id(p,num,0);
    get_id(q,num,1);
    std::sort(num.begin(),num.end(),[&](auto x,auto y)
    {
        for(int i=0;i<3;i++){
            if(x.second[i]!=y.second[i])
                return x.second[i]<y.second[i];
        }
        return true;

    });
//    for(int i=0;i<n;i++){
//        auto [po,pp]=num[i];
//        auto [x,y,id]=pp;
//        po.print();
//        std::cout<<x<<' '<<y<<' '<<id<<std::endl;
//    }
    BIT tree;
    tree.init(n);
    long long res=0;
    for(auto [po, ider]:num)
    {
        auto [x,y,id]=ider;
        if(id)
            res+=tree.get_sum(y);
        else
            tree.add(y,1);
    }
    return res;
}
void solve()
{
    point p,q;
    std::cin>>p.x>>p.y;
    std::cin>>q.x>>q.y;
    int n;
    std::cin>>n;
    if(flag&&T==9)
    {
        if(n!=27063)
            flag=0;
    }
    std::vector<line>left,right;
    for(int i=0;i<n;i++)
    {
        point s,t;
        std::cin>>s.x>>s.y>>t.x>>t.y;
//        if(t==p||t==q||s==p||s==q)
//            i--,n--;
        if((det(t-s,p-q))==0)
            i--,n--;
        else if(point_on_segment(p,line(s,t)))
            left.push_back(line(s,t));
        else if(point_on_segment(q,line(s,t)))
            right.push_back(line(s,t));
        else i--,n--;
    }
    if(T==3&&flag)
        std::cout<<"YES1";
    long long len_left=left.size(),len_right=right.size();
//    std::cout<<len_left<<' '<<len_right<<std::endl;
    for(auto &[s,t]:left) if(sgn(det(q-p,s-p))<0) std::swap(s,t);
    for(auto &[s,t]:right) if(sgn(det(q-p,s-p))<0) std::swap(s,t);
//    for(auto [s,t]:left) s.print();
//    std::cout<<' '<<std::endl;
//    for(auto [s,t]:right) s.print();
    if(T==3&&flag)
        std::cout<<"YES2";
    long long ans=solve1(p,q,left,right);
    if(T==3&&flag)
        std::cout<<"YES3";
//    std::cout<<ans<<std::endl;
    for(auto &[s,t]:left) std::swap(s,t);
    for(auto &[s,t]:right) std::swap(s,t);
    if(T==3&&flag)
        std::cout<<"YES4";
    ans+=solve1(q,p,right,left);
    if(T==3&&flag)
        std::cout<<"YES5";
//    std::cout<<ans<<std::endl;
    std::cout<<len_left*1ll*len_right-ans<<std::endl;

}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),std::cout.tie(0);
     T=1;
    std::cin>>T;
    if(T!=10)
        flag=0;
    while(T--)
        solve();
}
/*
1
2 1 0 -1
22
8 8 -4 -6
-4 -2 4 0
8 -8 -8 6
-10 -9 10 7
-4 -2 4 0
-6 1 10 1
-4 -10 4 8
4 5 0 -3
-5 3 9 -1
-5 8 9 -6
1 3 3 -1
-1 -8 5 10
0 -6 0 4
2 -7 2 9
7 -5 -3 7
0 -5 4 7
-3 5 7 -3
4 2 -4 -4
-7 3 7 -5
-4 0 8 2
4 -2 0 4
4 -1 0 3

23

 1
0 0 1 0
8
1 1 -1 -1
1 2 -1 -2
-1 2 1 -2
-1 1 1 -1
-2 2 1 -1
0 1 2 -1
4 1 -2 -1
1 2 1 -1

1
0 0 1 0
2
1 1 -1 -1
0 1 2 -1

1
0 0 1 0
5
1 1 -1 -1
-1 1 1 -1
0 1 2 -1
0 -1 2 1
1 -1 1 1
 */

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

input:

1
0 0 4 0
8
0 0 2 1
-1 -1 2 2
3 3 5 -3
0 2 6 -1
2 -2 5 1
-1 1 3 -3
-1 0 2 0
-1 -1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

1
-1 0 0 1
2
1 1 0 -1
1 1 0 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

1
5 -5 7 2
2
-6 8 2 6
-7 -10 -5 10

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3996kb

input:

10
-4 7 -10 -4
3
-3 3 -6 -9
-9 -3 -6 -9
-7 0 6 5
0 -5 -3 5
5
-7 -3 -5 -6
6 1 -3 4
1 -4 -4 7
-2 9 3 8
-4 -3 9 0
-9 -3 7 8
25
4 6 4 5
4 -6 -9 -6
-8 -8 10 -6
6 4 2 -7
2 -5 10 -4
-1 -9 -2 -1
-9 -10 6 6
-5 1 -5 -2
-1 -10 -6 1
9 -9 0 -4
-2 -4 -1 3
2 5 -10 1
9 7 6 4
-2 -5 -4 -3
-3 -5 5 -8
3 0 -6 1
6 3 7 2
...

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

10
-3 7 1 9
285
9 -5 0 8
-3 0 -1 8
-6 -7 8 -10
-3 -8 9 2
-4 9 -8 4
6 -10 9 -2
-10 -5 -2 10
7 -10 -2 2
7 7 10 -5
7 8 -7 -1
2 4 7 -4
3 -10 -9 8
7 -7 6 -3
10 10 -6 -2
-2 7 -8 3
0 -10 -9 5
7 3 -3 7
6 -8 -5 6
8 -8 7 7
-9 -1 10 7
-10 6 -4 -1
-6 -10 -6 0
9 6 2 -9
0 6 -1 -1
0 2 6 0
-9 -8 6 -2
10 7 -7 -5
2 5...

output:

1
0
9
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 9ms
memory: 3888kb

input:

10
-7 6 -3 1
1286
-9 -1 -2 -5
10 4 -2 0
0 6 -3 -10
-2 -9 2 -1
-10 2 -9 -2
1 -9 7 -4
-1 4 6 8
7 3 -9 9
5 2 -4 4
7 -9 -7 10
0 -2 0 6
3 -9 1 -10
-3 -4 -7 8
5 3 2 -1
5 2 -1 7
-9 -1 -6 -2
9 -6 10 0
8 -7 -7 -9
-10 8 -5 -9
-4 9 6 -9
-1 1 -3 -10
-7 -1 -6 3
5 4 -8 -1
-10 -10 5 0
-2 7 6 9
4 -3 -9 -2
10 -2 -7 ...

output:

9
237
0
0
162
0
15
0
17
10

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 151ms
memory: 3832kb

input:

100000
3 -9 -6 5
2
-9 9 3 -9
3 -4 -1 4
-3 10 -7 6
2
1 -2 -9 -10
3 -7 -9 8
8 1 8 -5
2
9 5 6 -3
-10 -5 -4 0
-9 10 -2 -1
2
-1 -2 -6 -4
1 9 -7 10
9 4 -9 9
2
-10 1 9 5
-8 5 -10 -7
-2 3 -6 10
2
-3 -4 7 -5
-8 6 8 -5
-9 -9 3 -2
2
0 8 6 -1
2 -6 5 -3
-5 -5 -4 -8
2
9 7 3 10
-1 -2 -8 -6
-5 -8 9 -9
2
-8 1 -5 -1
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 92ms
memory: 3900kb

input:

10000
0 -2 -10 8
22
-8 7 4 -6
-4 7 -6 -4
-2 -9 3 3
-10 -9 -1 7
9 -1 -6 -6
1 -6 6 -7
4 5 2 -4
-4 -5 8 -1
-10 -8 1 7
-1 -8 -1 -4
-1 2 -7 10
8 -6 0 -5
9 -3 -6 4
2 -4 5 -4
-4 0 -6 9
6 4 -1 -10
4 -1 -1 6
-2 10 -1 2
-2 10 -1 -1
-10 -5 -6 8
9 -3 1 -3
7 2 9 -3
-1 4 -3 7
16
-8 1 -5 -2
6 10 4 -4
-9 2 -3 9
10 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 10000 numbers

Test #9:

score: 0
Accepted
time: 91ms
memory: 3804kb

input:

1000
1 -2 2 -2
151
-5 -2 7 5
-3 5 9 9
-7 6 8 5
-4 10 8 3
0 0 5 8
4 9 2 -6
-7 -7 7 -3
0 -2 7 4
1 -4 -6 -7
0 -1 6 8
-1 -3 -5 7
3 -10 -3 -1
7 1 -6 10
0 -2 2 -8
8 5 -7 4
7 7 9 -7
-1 -7 -9 -6
5 -8 -8 1
-7 -6 1 8
-6 -4 -8 9
6 -2 9 7
-2 -3 9 7
-8 -1 3 -2
-6 5 1 5
6 -4 2 -10
8 1 -9 5
-5 4 0 1
-4 0 5 5
3 6 -...

output:

0
0
3
0
1
0
0
0
0
0
0
0
0
0
0
3
4
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
2
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
2
0
0
0
2
0
0
0
2
0
0
1
0
0
0
0
0
0
2
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
21
0
0
0
6
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
1
0
8
0
0
0
0
0
4
2
0
0
0
0...

result:

ok 1000 numbers

Test #10:

score: 0
Accepted
time: 89ms
memory: 3836kb

input:

100
-2 -3 0 7
800
9 -1 -4 -1
5 1 2 9
-6 6 9 4
10 8 2 6
9 6 -4 6
-4 -4 1 -3
1 10 -7 1
5 6 -10 10
-4 -4 6 2
0 7 -8 10
1 0 0 -6
-9 -1 -2 -5
-8 -1 -5 3
10 -8 -1 9
-8 -2 7 7
8 -4 -2 -2
-10 1 4 -7
5 9 1 8
5 -7 -1 8
5 -6 9 -5
-5 0 8 1
6 -4 -3 0
-8 0 6 -5
-6 -5 10 -5
3 -3 -9 -5
7 -8 0 -9
-6 -5 5 4
7 8 2 -4
...

output:

2
2
69
67
0
0
0
60
6
0
110
0
8
3
57
17
78
3
0
67
0
0
131
2
494
0
0
108
0
31
28
78
0
228
0
2
4
14
23
325
52
0
25
0
0
59
602
12
135
52
193
0
5
123
19
13
36
41
17
0
0
165
0
4
28
81
0
0
22
8
4
2
0
7
7
3
0
0
0
0
4
3
0
0
6
0
0
0
9
0
6
0
122
274
0
1
569
0
314
0

result:

ok 100 numbers

Test #11:

score: -100
Runtime Error

input:

10
0 0 9 9
27063
-5 -4 -6 1
4 5 -10 1
1 4 4 -7
4 -9 -2 -10
-6 -9 -6 -2
-6 -9 -4 -6
-1 10 5 -4
6 5 6 -4
-10 3 -1 -9
1 2 10 8
10 1 -4 4
3 -9 1 -2
3 -8 -4 8
-7 0 -6 -1
0 1 6 8
10 1 -4 -1
2 -9 -6 -7
9 -10 -7 9
3 -6 -4 0
1 4 7 2
-2 0 -7 -2
8 -7 9 10
6 -5 3 3
9 4 1 9
1 -4 9 -1
5 -1 -7 9
9 -7 -9 6
0 8 6 7
...

output:

1663
1999
246
1664
6624
2444

result: