QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97704#6327. Count Arithmetic ProgressionBazoka13WA 190ms94472kbC++1416.5kb2023-04-17 22:57:222023-04-17 22:57:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-17 22:57:25]
  • 评测
  • 测评结果:WA
  • 用时:190ms
  • 内存:94472kb
  • [2023-04-17 22:57:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define pi acos(-1.0)
#define pb push_back
#define eps 1e-9
#define db double
int sgn(double x){
    if(fabs(x)<eps)return 0;
    if(x<0)return -1;
    return 1;
}
double cmp(double a,double b){return sgn(a-b);}
double sqr(double x){return x*x;}
double inmid(double x,double l,double r){return sgn(x-l)>=0&&sgn(r-x)>=0;}
struct Point{
    double x,y;
    Point(){}
    Point(double xx,double yy){x=xx;y=yy;}
    void input(){scanf("%lf %lf",&x,&y);}
    void output(){printf("%.0f %.0f\n",x,y);}
    bool operator ==(const Point &p)const{return sgn(x-p.x)==0&&sgn(y-p.y)==0;}
    bool operator !=(const Point &p)const{return sgn(x-p.x)!=0||sgn(y-p.y)!=0;}
    bool operator < (const Point &p)const{
        return sgn(x-p.x)<0||(sgn(x-p.x)==0&&sgn(y-p.y)<0);
    }
    Point operator + (const Point &p)const{
        return {x+p.x,y+p.y};
    }
    Point operator - (const Point &p)const{
        return {x-p.x,y-p.y};
    }
    Point operator * (double k)const{
        return {x*k,y*k};
    }
    Point operator / (const double &k)const{
//assert(k!=0);
        return {x/k,y/k};
    }
    double dot(Point p) const{return p.x*x+p.y*y;}
    double cross(Point p) const {return x * p.y - y * p.x;}
    double dis(Point p) const {return sqrt(sqr(x - p.x) + sqr(y - p.y));}
    double abs() const{return sqrt(sqr(x)+sqr(y));}
    double abs2() const{return sqr(x)+sqr(y);}
    Point rot(Point p,double a){
//閫嗘椂閽堟棆杞?
        Point v = (*this) - p;
        double c = cos(a), s = sin(a);
        return Point(p.x + v.x*c - v.y*s,p.y + v.x*s + v.y*c);
    }
    Point rotLeft() const{return Point(-y,x);}
    Point rotRight() const{return Point(y,-x);}
    double getW() const{return atan2(y,x);}
    Point unit()const{
        if(sgn(abs())==0)return (*this);
        else return {x/abs(),y/abs()};
    }
    Point trunc(double r)const{Point tmp=unit();return tmp*r;}
    double rad(Point a,Point b)const{
        Point k1=a-(*this),k2=b-(*this);
        return atan2(k1.cross(k2), k1.dot(k2));
    }
};
double cross(Point p1,Point p2,Point p3){
    return (p2-p1).cross(p3-p1);
}
double dot(Point p1,Point p2,Point p3){
    return (p2-p1).dot(p3-p1);
}
struct Line{
    Point s,e;//鏈夊悜鐩寸嚎
    double ang;
    ll k,b;
    Line(){}
    Line(Point ss,Point ee){s=ss;e=ee;}
    void input(){s.input();e.input();}
    bool operator ==(const Line &v)const{return s==v.s&&e==v.e;}
    double len(){return (e-s).abs();}
    void calcAng(){ang= atan2(dir().y,dir().x);}
    Point dir(){return e-s;}
    ll getY(ll x){
        double dx1=e.x-s.x;
        double dx2=x-s.x;
        double dy1=e.y-s.y;
        ll dy2=s.y+dy1*(dx2/dx1);
        return dy2;
    }
    int checkLP(Point p){
/* s e p make a counterclockwise 1
* s e p make a clockwise 2
* p is on a line p s e 3
* p is on a line s e p 4
* p is on a seg s e 5
* error 6 */
        int tmp = sgn(cross(s,p,e));
        if(tmp<0)return 1;
        if(tmp>0)return 2;
        int dt=sgn(dot(p,s,e));
        if(dt<=0)return 5;
        if(sgn(dot(s,p,e))>0)return 4;
        if(sgn(dot(s,p,e))<0)return 3;
        assert(0);
    }
    int checkLL(Line v){
// 3 coincide 2 parallel 1 orthogonal 0 others
        int tmp = sgn((e-s).cross(v.e-v.s));
        if(tmp==0){
            if(v.checkLP(e)>2)return 3;
            return 2;
        }
        if(sgn((e-s).dot(v.e-v.s))==0)return 1;
        return 0;
    }
    int checkSS(Line v){
// 2 not strict 1 strict 0 not ins
        if(checkLP(v.s)==5|| checkLP(v.e)==5)return 2;
        if(v.checkLP(s)==5||v.checkLP(e)==5)return 2;
        int tmp=sgn(cross(s,e,v.s)* cross(s,e,v.e));
        int tmp2=sgn(cross(v.s,v.e,s)* cross(v.s,v.e,e));
        if(tmp<0&&tmp2<0)return 1;
        return 0;
    }
    int checkLS(Line v){//untested 2涓ユ牸1涓嶄弗鏍?
        int d1 = sgn((e-s).cross(v.s-s));
        int d2 = sgn((e-s).cross(v.e-s));
        if((d1^d2)==-2) return 2;
        return (d1==0||d2==0);
    }
    Point getLL(Line v){
        double tmp=(s-v.s).cross(v.e-v.s),tmp2=(v.e-v.s).cross(e-v.s);
        return (s*tmp2+e*tmp)/(tmp+tmp2);
    }
    Point proj(Point p){
        return s+(e-s).trunc(dot(s,p,e)/len());
    }
    Point ref(Point p){
        Point tmp= proj(p);
        return tmp+tmp-p;
    }
    double disLP(Point p){return p.dis(proj(p));}
    double disSP(Point p){
        if(checkLP(proj(p))!=5)return min(p.dis(s),p.dis(e));
        return disLP(p);
    }
    double disSS(Line v){
        if(checkSS(v))return 0.0;
        return min({disSP(v.s), disSP(v.e),v.disSP(s),v.disSP(e)});
    }
    Line trans(Point v,double d){
        Point tmp=v.trunc(d);
        return {s+tmp,e+tmp};
    }
    Line transLeft(double d){return trans((e-s).rotLeft(),d);}
    Line transRight(double d){return trans((e-s).rotRight(),d);}
};
bool onSeg(Point p,Point a,Point b){return Line(a,b).checkLP(p)==5;}
struct Circle{
    Point p;
    double r;

    Circle(){}
    Circle(Point pp,double rr){p=pp;r=rr;}
    bool operator == (const Circle &c)const{
        return (p==c.p)&&(sgn(r-c.r)==0);
    }
    Point point(double a){return p+Point(r*cos(a),r*sin(a));}
    void input(){p.input();scanf("%lf",&r);}
    int include(Point q){if(sgn(p.dis(q)-r)==0)return 1;if(sgn(p.dis(q)-r)
                                                           <0)return 2;return 0;}
    int checkCC(Circle c){
//0 鍐呭惈 1 鍐呭垏 2 鐩镐氦 3 澶栧垏 4 鐩哥
        double d=c.p.dis(p);
        if(sgn(d-r-c.r)>0)return 4;
        if(sgn(d-r-c.r)==0)return 3;
        if(sgn(d- fabs(r-c.r))==0)return 1;
        if(sgn(d- fabs(r-c.r))<0)return 0;
        return 2;
    }
    int checkCL(Line l){
//2 鐩镐氦 1鐩稿垏 0 鐩哥
        if(sgn(l.disLP(p)-r)==0)return 1;
        if(sgn(l.disLP(p)-r)<0)return 2;
        return 0;
    }
    vector<Point> getCL(Line v){
//鐩稿垏缁欏嚭涓や釜
        if(checkCL(v)==0)return {};
        vector<Point> tmp;
        double d=v.disLP(p);
        double x=sqrt(r*r-d*d);
        if(sgn(d-r)==0){
            tmp.pb(v.proj(p));
            tmp.pb(v.proj(p));
        }else{
            tmp.pb(v.proj(p)-(v.e-v.s).trunc(x));
            tmp.pb(v.proj(p)+(v.e-v.s).trunc(x));
//鍜寁鏂瑰悜涓€鑷?
        }
        return tmp;
    }
    double circ(){return 2*pi*r;}
    double area(){return pi*r*r;}
    vector<Point> getCC(Circle c){//娌垮綋鍓嶉€嗘椂閽堢粰鍑?鐩稿垏缁欏嚭涓や釜
        if(checkCC(c)==0|| checkCC(c)==4)return {};
        double b=p.dis(c.p),cosA=(r*r+b*b-c.r*c.r)/(2*r*b);
        double tmp=r*cosA,h=sqrt(r*r-tmp*tmp);
        Point v=(c.p-p).trunc(tmp).rotLeft().trunc(h);
        Point ini=p+(c.p-p).trunc(tmp);
        return {ini-v,ini+v};
    }
    vector<Point> TangentCP(Point q){
        if(include(q)==2)return {};
        if(include(q)==1)return {q,q};
//        double cosA=r/p.dis(q),h=sqrt(sqr(r)- sqr(r*cosA));
//        Point ini=(q-p).trunc(r*cosA),v=ini.rotLeft().trunc(h);
//        return {p+ini-v,p+ini+v};
        db d = (q - p).abs2();
        db x = d - sqr(r);
        Point q1 = (q - p) * sqr(r) / d;
        Point q2 = ((q -p) * -r * sqrtl(x) / d).rotLeft();
        return {p+q1-q2,p+q1+q2};
    }
    Point getPoint(double t){
        return p+Point(r* cos(t),r* sin(t));
    }
    double insCC(Circle c){
        if(checkCC(c)<2)return pi*sqr(min(r,c.r));
        if(checkCC(c)>2)return 0.0;
        double d=(p-c.p).abs();
        double x=(d*d+r*r-c.r*c.r)/(2*d);
        double t1= acos(x/r),t2= acos((d-x)/c.r);
        return sqr(r)*t1+sqr(c.r)*t2-d*r* sin(t1);
    }
    double insCT(Point a,Point b){
        auto tmp= getCL({a,b});
        if(tmp.empty())return r*r*p.rad(a,b)/2.0;
        int i1= include(a),i2= include(b);
        if(i1==0&&i2==0){
            if(sgn((a-p-tmp[0]).dot((b-p-tmp[0])))<=0&&
               sgn((a-p-tmp[1]).dot((b-p-tmp[1])))<=0
                    ){
                return (sqr(r)*(p.rad(a,b)-p.rad(tmp[0],tmp[1]))+(tmp[0]-
                                                                  p).cross(tmp[1]-p))/2.0;
            }else return sqr(r)*p.rad(a,b)/2.0;
        }else if(i1==0){
            return (sqr(r)*p.rad(a,tmp[0])+(tmp[0]-p).cross(b-p))/2.0;
        }else if(i2==0){
            return (sqr(r)*p.rad(tmp[1],b)+(a-p).cross(tmp[1]-p))/2.0;
        }else return (a-p).cross(b-p)/2.0;
    }
    double insCP(const vector<Point> &poly){
        int sz=poly.size();
        double ans=0.0;
        for(int i=0;i<sz;i++){
            int j=(i+1)%sz;
            ans+= insCT(poly[i],poly[j]);
        }
        return fabs(ans);
    }
    double Green_Circle(double t1,double t2){
        return r*(r*(t2-t1)+p.x*(sin(t2)-sin(t1))-p.y*(cos(t2)-cos(t1)));
    }
};
Circle outTri(Point a,Point b,Point c){//澶栨帴鍦?
    Line l={(a+b)/2.0,(a+b)/2.0+((a-b)/2.0).rotLeft()};
    Line r={(c+b)/2.0,(c+b)/2.0+((c-b)/2.0).rotLeft()};
    return {l.getLL(r),a.dis(l.getLL(r))};
}
Circle inTri(Point a,Point b,Point c){
    double d1=((a-c).getW()+(b-c).getW())/2,d2=((c-a).getW()+(b-a).getW())/2;
    Line tmp={c,c+Point(cos(d1), sin(d1))},tmp2={a,a+Point(cos(d2), sin(d2))};
    return {tmp.getLL(tmp2),Line(a,b).disLP(tmp.getLL(tmp2))};
}
vector<Line> TangentOutCC(Circle a,Circle b){
    if(a.checkCC(b)<2)return {};
    if(sgn(a.r-b.r)==0){
        return {{a.p+(b.p-a.p).trunc(a.r).rotLeft(),b.p+(a.p-b.p).trunc(b.r).rotRight()},
                {a.p+(b.p-a.p).trunc(a.r).rotRight(),b.p+(a.p-b.p).trunc(b.r).rotLeft()}};
    }
    int fl=sgn(a.r-b.r)>0?0:1;
    if(fl)swap(a,b);
    double alpha=acos((a.r-b.r)/(a.p.dis(b.p)));
    Point tmp=a.p+(b.p-a.p).rot({0,0},alpha).trunc(a.r),tmp2=a.p+(b.p-a.p).rot({0,0},-alpha).trunc(a.r);
    Point tmp3=b.p+(a.p-b.p).rot({0,0},-(pi-alpha)).trunc(b.r),tmp4=b.p+(a.p-b.p).rot({0,0},pi-alpha).trunc(b.r);
    if(fl)swap(tmp,tmp3), swap(tmp2,tmp4), swap(a,b);
    return {{tmp,tmp3},{tmp2,tmp4}};
}
vector<Line> TangentInCC(Circle a,Circle b){
    if(a.checkCC(b)==1|| a.checkCC(b)==3){
        Point tmp= a.getCC(b)[0];
        return {{tmp,tmp+(a.p-tmp).rotLeft()}};
    }else if(a.checkCC(b)!=4)return {};
    Point mid=a.p+(b.p-a.p)*(a.r/(a.r+b.r));
    auto l= a.TangentCP(mid),rr=b.TangentCP(mid);
    vector<Line> tmp;
    for(int i=0;i<l.size();i++){tmp.pb({l[i],rr[i]});}
    return tmp;
}
vector<Line> TangentCC(Circle a,Circle b){//鍐呭垏瑙嗕綔浜員angentInCC
    auto inc = TangentInCC(a,b),outc= TangentOutCC(a,b);
    vector<Line> tmp;
    for(auto i:inc)tmp.push_back(i);for(auto i:outc)tmp.push_back(i);
    return tmp;
}
double polyArea(const vector<Point> &p){
    double ans=0;
    int sz=p.size();
    for(int i=0;i<sz;i++){
        ans+=(p[i].cross(p[(i+1)%sz]));
    }
    return fabs(ans)/2.0;
}
double polyCir(const vector<Point> &p){
    double ans=0;
    int sz=p.size();
    for(int i=0;i<sz;i++){
        ans+=(p[i].dis(p[(i+1)%sz]));
    }
    return ans;
}
bool isConvex(const vector<Point> &p,int flag=0){//0 涓ユ牸 1 闈炰弗鏍?counterclockwise
    int sz=p.size();
    for(int i=0;i<sz;i++){
        int x=Line(p[i],p[(i+1)%sz]).checkLP(p[(i+2)%sz]);
        if(x!=1){
            if(flag){if(x==2)return false;}
            else return false;
        }
    }
    return true;
}
int contain(vector<Point> ps, Point p){ //2:inside 1:onSeg 0:outside
    int n = ps.size(), ret = 0;
    for(int i=0;i<n;i++){
        Point u=ps[i],v=ps[(i+1)%n];
        if(onSeg(p,u,v)) return 1;
        if(cmp(u.y,v.y)<=0) swap(u,v);
        if(cmp(p.y,u.y) >0 || cmp(p.y,v.y) <= 0) continue;
        ret ^= sgn(cross(p,u,v)) > 0;
    }
    return ret*2;
}
vector<Point> convexCut(const vector<Point>&ps, Point q1, Point q2) {
    vector<Point> qs;
    int n = ps.size();
    for(int i=0;i<n;i++){
        Point p1 = ps[i], p2 = ps[(i+1)%n];
        int d1 = sgn(cross(q1,q2,p1)), d2 = sgn(cross(q1,q2,p2));
        if(d1 >= 0) qs.pb(p1);
        if(d1 * d2 < 0) qs.pb(Line(p1,p2).getLL({q1,q2}));
    }
    return qs;
}
double convexDiameter(vector<Point> ps){
    int n = ps.size(); if(n <= 1) return 0;
    int is = 0, js = 0;
    for(int k=0;k<n;k++)is=ps[k]<ps[is]?k:is, js = ps[js] < ps[k]?k:js;
    int i = is, j = js;
    double ret = ps[i].dis(ps[j]);
    do{
        if((ps[(i+1)%n]-ps[i]).cross(ps[(j+1)%n]-ps[j]) >= 0)
            (++j)%=n;
        else
            (++i)%=n;
        ret = max(ret,ps[i].dis(ps[j]));
    }while(i!=is || j!=js);
    return ret;
}
vector<Point> convexHull(vector<Point>A, int flag = 1) { // flag=0 涓嶄弗鏍?flag=1 涓ユ牸
    int n = A.size(); vector<Point>ans(n * 2);
    if(n==1)return A;
    sort(A.begin(), A.end()); int now = -1;
    for (int i = 0; i < A.size(); i++) {
        while (now > 0 && sgn(cross(ans[now-1],ans[now],A[i]))<flag)now--;
        ans[++now] = A[i];
    } int pre = now;
    for (int i = n - 2; i >= 0; i--) {
        while (now > pre && sgn(cross(ans[now-1],ans[now],A[i]))<flag)now--;
        ans[++now] = A[i];
    } ans.resize(now); return ans;
}
vector<Point> norm(vector<Point> p,Point q){//鏋佽鎺掑簭
    sort(p.begin(),p.end(),[&](Point a,Point b){
        int d = sgn((a-q).cross(b-q));
        if(d == 0){
            return sgn(a.dis(q)-b.dis(q)) < 0;
        }
        return d > 0;
    });
    return p;
}
vector<Point> graHam(vector<Point> ps){
    auto mi=ps[0];
    for(auto i:ps)mi=min(mi,i);
    ps = norm(ps,mi);
    int n=ps.size();
    vector<Point> ans(n*2);
    int top = 0;
    if(n == 1){
        top = 1;
        ans[0] = ps[0];
    }else if(n == 2){
        top = 2;
        ans[0] = ps[0];
        ans[1] = ps[1];
        if(ans[0] == ans[1])top--;
    }else{
        ans[0] = ps[0];
        ans[1] = ps[1];
        top = 2;
        for (int i = 2; i < n; i++) {
            while (top > 1 &&
                   sgn((ans[top-1]-ans[top - 2]).cross(ps[i]-ans[top-2]))<=0)
                top--;
            ans[top++] = ps[i];
        }
        if (top== 2 && (ans[0] == ans[1]))top--;
    }
    ans.resize(top);return ans;
}
vector<Point> getHL(vector<Line> &L) {//璁板緱calcAng ==2鍙互鍖呭惈鍏辩嚎 !=1涓嶅寘鍚?
    int n = L.size();
    for(int i=0;i<n;i++)L[i].calcAng();
    sort(L.begin(), L.end(),[&](Line a,Line b){return sgn(a.ang-b.ang)<0;});
    int first, last;
    vector<Point> p(n);
    vector<Line> q(n);
    vector<Point> ans;
    q[first = last = 0] = L[0];
    for (int i = 1; i < n; i++) {
        while (first < last && L[i].checkLP(p[last - 1])!=1)last--;
        while (first < last && L[i].checkLP(p[first])!=1)first++;
        q[++last] = L[i];
        if (sgn((q[last].dir().cross(q[last - 1].dir())))==0) {
            last--;
            if (q[last].checkLP(L[i].s)==1) q[last] = L[i];
        }
        if (first < last) p[last - 1] = q[last - 1].getLL(q[last]);
    }
    while (first < last && q[first].checkLP(p[last - 1])!=1) last--;
    if (last - first <= 1) return ans;
    p[last] = q[last].getLL(q[first]);
    for (int i = first; i <= last; i++)
        ans.push_back(p[i]);
    return ans;
}
const int N = 3e5+10;
ll l[N],r[N];
ll qpow(ll a,ll k){
    ll ans=1ll;
    ll mod=998244353;
    while(k){
        if(k&1)ans=ans*a%mod;
        a=a*a%mod;
        k>>=1;
    }
    return ans%mod;
}
ll gcd(ll a, ll b) {
    while (b != 0) {
        ll tmp = a;
        a = b;
        b = tmp % b;
    }
    return a;
}
ll absl(ll x){
    if(x<0)return -x;
    return x;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        long long tmp;
        scanf("%lld",&tmp);
        l[i]=tmp;
    }
    for(int i=1;i<=n;i++){
        long long tmp;
        scanf("%lld",&tmp);
        r[i]=tmp;
    }
    vector<Line> ls;
    for(int i=1;i<=n;i++){
        int j=i-1;
        ls.push_back({{1,(double)l[i]-j},{2,(double)l[i]-2*j}});
        ls.push_back({{2,(double)r[i]-2*j},{1,(double)r[i]-j}});
    }
    auto ch = getHL(ls);

    int sz=ch.size();
    double s= polyArea(ch);
    ll tot=0;
    for(int i=0;i<sz;i++){
        int j=(i+1)%sz;
        ll xr=ch[j].x;
        ll xl=ch[i].x;
        ll yr=ch[j].y;
        ll yl=ch[i].y;
        ll g=gcd(absl(xr-xl),absl(yr-yl));
        tot=(tot+g)%998244353;
    }
    if(sz==0){
        puts("0");
        return 0;
    }
    ll mod=998244353;
    ll ans=((ll)s+1ll)%mod+tot*qpow(2,998244351)%mod;
    ans%=998244353;
    printf("%lld\n",(long long)ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5980kb

input:

3
5 5 2
7 6 7

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

4
2 3 1 6
5 6 4 8

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 190ms
memory: 94472kb

input:

300000
121398540794 60081434790 252920491076 43666218735 95583832019 21178121624 315727133812 89837170656 138389231466 174687947367 124350262341 108583578309 289629745492 321006985392 301201031648 138149017169 255983300245 138801256482 285614769875 130583757928 261690466826 74624776159 303504239011 ...

output:

644943019

result:

wrong answer 1st numbers differ - expected: '2000014', found: '644943019'