QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#49893#4813. DS Team SelectionCrysflyAC ✓17870ms65144kbC++1712.1kb2022-09-23 22:54:312022-09-23 22:54:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-23 22:54:32]
  • 评测
  • 测评结果:AC
  • 用时:17870ms
  • 内存:65144kb
  • [2022-09-23 22:54:31]
  • 提交

answer

// for test.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;

const int MAXN=1e5;

inline int Read()
{
    int ret=0,sgn=1;char c;
    while(1) {c=getchar();if('0'<=c && c<='9') {ret=c-'0';break;}}
    while(1) {c=getchar();if('0'<=c && c<='9') ret=ret*10+c-'0';else break;}
    return sgn*ret;
}

int dsc[4*MAXN+5],dnum;//离散化 
struct BIT
{
    ui sum[4*MAXN+5];int Edit[4*MAXN+5],New;
    inline int lowbit(int x) {return x&-x;}
    inline void upd(int x) {if(Edit[x]<New) Edit[x]=New,sum[x]=0;}
    inline void Clean() {++New;}
    inline void Plus(int x,ui v) {for(;x<=dnum;x+=lowbit(x)) upd(x),sum[x]+=v;}
    inline ui Ask(int x)
    {
        ui ret=0;
        for(;x>0;x-=lowbit(x)) upd(x),ret+=sum[x];
        return ret;
    }
}mapn[6];

inline int Search(int x)
{
    for(int L=1,R=dnum,mid;1;)
    {
        mid=(L+R)>>1;
        if(dsc[mid]==x) return mid;
        if(dsc[mid]<x) L=mid+1;
        else R=mid-1;
    }
    return 0;
}

int n;
ui ans[MAXN+5];int anum;

struct Query
{
    int opt,a,b,c,d,ID;//查询编号 
    inline void Scan() {opt=Read(),a=Read(),b=Read(),c=Read(),d=Read();}
}qry[MAXN+5];

struct Ope
{
    int x,y;//y 离散化后结果 
    ui val[6];
    int ID,Time;//0 修改 >0 查询编号,Time 时间戳 
}ope[4*MAXN+5],lef[2*MAXN+5],rig[2*MAXN+5];int onum,lnum,rnum;
inline bool cmp(Ope a,Ope b) {return (a.x==b.x ? a.ID<b.ID : a.x<b.x);}

void CDQ(int L,int R,int lim)
{
    //斜线:0~5 水平:6~11
    if(L==R) return;
    int mid=(L+R)>>1;
    CDQ(L,mid,lim),CDQ(mid+1,R,lim);
    lnum=rnum=0;
    for(int i=L;i<=mid;i++) lef[++lnum]=ope[i];
    for(int i=mid+1;i<=R;i++) rig[++rnum]=ope[i];
    for(int i=L,j=1,k=1;i<=R;i++)
        if(j<=lnum && k<=rnum)
        {
            if(cmp(lef[j],rig[k])) ope[i]=lef[j++];
            else ope[i]=rig[k++];
        }
        else if(j<=lnum) ope[i]=lef[j++];
        else ope[i]=rig[k++];
    for(int i=0;i<lim;i++) mapn[i].Clean();
    for(int i=L;i<=R;i++)
        if(!ope[i].ID && ope[i].Time<=mid)
            for(int j=0;j<lim;j++) mapn[j].Plus(ope[i].y,ope[i].val[j]);
        else if(ope[i].ID && ope[i].Time>mid)
            for(int j=0;j<lim;j++) ans[ope[i].ID]+=ope[i].val[j]*mapn[j].Ask(ope[i].y);
}

struct msg {int x,y,d,w,ID;}trg[4*MAXN+5];int tnum;
inline void Discre()
{
    for(int i=1;i<=onum;i++) dsc[i]=ope[i].y;
    sort(dsc+1,dsc+onum+1),dnum=unique(dsc+1,dsc+onum+1)-dsc-1;
    for(int i=1;i<=onum;i++) ope[i].y=Search(ope[i].y);
}
Ope Copy[4*MAXN+5];
inline void Solve()//解决一组三角形覆盖二位前缀和查询
{
    //情况一,斜线贡献 
    onum=0;
    for(int i=1;i<=tnum;i++)
        if(trg[i].ID)//查询
        {
            ui xy=trg[i].x+trg[i].y,yx=trg[i].y-2*trg[i].x;

            ope[++onum].x=trg[i].x;
            ope[onum].y=trg[i].x+trg[i].y;
            ope[onum].val[0]=xy*xy*yx;
            ope[onum].val[1]=xy*xy;
            ope[onum].val[2]=xy*yx;
            ope[onum].val[3]=xy;
            ope[onum].val[4]=yx;
            ope[onum].val[5]=1;
            if(trg[i].w<0) for(int j=0;j<6;j++) ope[onum].val[j]*=-1;
            ope[onum].ID=trg[i].ID;
            ope[onum].Time=onum;
        }
        else//修改 
        {
            ui p=-trg[i].x-trg[i].y+trg[i].d,q=-trg[i].y+trg[i].d+1;
            ui r=3*q-2*p-1,p1=2*p+1,pp=p*(p+1);

            ope[++onum].x=trg[i].x-trg[i].d+1;
            ope[onum].y=trg[i].x+trg[i].y-trg[i].d+1;
            ope[onum].val[0]=trg[i].w;
            ope[onum].val[1]=trg[i].w*r;
            ope[onum].val[2]=trg[i].w*p1;
            ope[onum].val[3]=trg[i].w*p1*r;
            ope[onum].val[4]=trg[i].w*pp;
            ope[onum].val[5]=trg[i].w*pp*r;
            ope[onum].ID=0;
            ope[onum].Time=onum;

            ++onum,ope[onum]=ope[onum-1];
            ope[onum].x=trg[i].x+1;
            for(int j=0;j<6;j++) ope[onum].val[j]*=-1;
            ope[onum].Time=onum; 
        }
    for(int i=1;i<=onum;i++) Copy[i]=ope[i];
    Discre(),CDQ(1,onum,6);
    //情况一,水平贡献
    onum=0;
    for(int i=1;i<=tnum;i++)
        if(trg[i].ID)
        {
            ++onum,ope[onum]=Copy[onum];
            ope[onum].y=trg[i].y;
        }
        else 
        {
            ++onum,ope[onum]=Copy[onum];
            ope[onum].x=trg[i].x+1;
            ope[onum].y=trg[i].y+1;

            ++onum,ope[onum]=Copy[onum];
            ope[onum].x=trg[i].x-trg[i].d+1;
            ope[onum].y=trg[i].y+1;
        }
    Discre(),CDQ(1,onum,6);
    //情况二
    onum=0;
    for(int i=1;i<=tnum;i++)
        if(trg[i].ID)
        {
            ui x=trg[i].x;

            ope[++onum].x=trg[i].x;
            ope[onum].y=trg[i].y;
            ope[onum].val[0]=x*x*x;
            ope[onum].val[1]=x*x;
            ope[onum].val[2]=x;
            ope[onum].val[3]=1;
            if(trg[i].w<0) for(int j=0;j<4;j++) ope[onum].val[j]*=-1;
            ope[onum].ID=trg[i].ID;
            ope[onum].Time=onum;
        }
        else
        {
            ui p=-trg[i].x+trg[i].d,q=trg[i].d+1;
            ui r=3*q-2*p-1,p1=2*p+1,pp=p*(p+1);

            ope[++onum].x=trg[i].x-trg[i].d+1;
            ope[onum].y=trg[i].y+1;
            ope[onum].val[0]=trg[i].w*(-2);
            ope[onum].val[1]=trg[i].w*(r-2*p1);
            ope[onum].val[2]=trg[i].w*(p1*r-2*pp);
            ope[onum].val[3]=trg[i].w*pp*r;
            ope[onum].ID=0;
            ope[onum].Time=onum;

            ++onum,ope[onum]=ope[onum-1];
            ope[onum].x=trg[i].x+1;
            for(int j=0;j<4;j++) ope[onum].val[j]*=-1;
            ope[onum].Time=onum;
        }
    Discre(),CDQ(1,onum,4);
    //情况三
    onum=0;
    for(int i=1;i<=tnum;i++)
        if(trg[i].ID)
        {
            ui y=trg[i].y;

            ope[++onum].x=trg[i].x;
            ope[onum].y=trg[i].y;
            ope[onum].val[0]=y*y*y;
            ope[onum].val[1]=y*y;
            ope[onum].val[2]=y;
            ope[onum].val[3]=1;
            if(trg[i].w<0) for(int j=0;j<4;j++) ope[onum].val[j]*=-1;
            ope[onum].ID=trg[i].ID;
            ope[onum].Time=onum;
        }
        else
        {
            ui p=-trg[i].y+trg[i].d,q=-trg[i].y+trg[i].d+1;
            ui r=3*q-2*p-1,p1=2*p+1,pp=p*(p+1);

            ope[++onum].x=trg[i].x+1;
            ope[onum].y=trg[i].y-trg[i].d+1;
            ope[onum].val[0]=trg[i].w;
            ope[onum].val[1]=trg[i].w*(r+p1);
            ope[onum].val[2]=trg[i].w*(pp+p1*r);
            ope[onum].val[3]=trg[i].w*pp*r;
            ope[onum].ID=0;
            ope[onum].Time=onum;

            ++onum,ope[onum]=ope[onum-1];
            ope[onum].y=trg[i].y+1;
            for(int j=0;j<4;j++) ope[onum].val[j]*=-1;
            ope[onum].Time=onum;
        }
    Discre(),CDQ(1,onum,4);
    //情况四
    onum=0;
    for(int i=1;i<=tnum;i++)
        if(trg[i].ID)
        {
            ope[++onum].x=trg[i].x;
            ope[onum].y=trg[i].y;
            ope[onum].val[0]=trg[i].w;
            ope[onum].ID=trg[i].ID;
            ope[onum].Time=onum;
        }
        else
        {
            ope[++onum].x=trg[i].x+1;
            ope[onum].y=trg[i].y+1;
            ope[onum].val[0]=trg[i].w*trg[i].d*(trg[i].d+1)*(trg[i].d+2);
            ope[onum].ID=0;
            ope[onum].Time=onum;
        }
    Discre(),CDQ(1,onum,1);
}

int main()
{
    n=Read();
    for(int i=1;i<=n;i++)
    {
        qry[i].Scan();
        if(qry[i].opt==2) qry[i].ID=++anum;
    } if(!anum)exit(0);
    //1.上下颠倒
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)//修改
        {
            if(qry[i].c<2) continue;
            trg[++tnum]=msg{qry[i].a+qry[i].c-1,-(qry[i].b+1),qry[i].c-1,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{qry[i].b,-qry[i].c,0,1,qry[i].ID};
            trg[++tnum]=msg{qry[i].a-1,-qry[i].c,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].b,-qry[i].d-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].a-1,-qry[i].d-1,0,1,qry[i].ID};
        }
    Solve();
    //2.顺时针 90 度 
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)
        {
            if(qry[i].c<3) continue;
            //(a+1,b+c-1)
            trg[++tnum]=msg{qry[i].b+qry[i].c-1,-(qry[i].a+1),qry[i].c-2,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{qry[i].d,-qry[i].a,0,1,qry[i].ID};
            trg[++tnum]=msg{qry[i].c-1,-qry[i].a,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].d,-qry[i].b-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].c-1,-qry[i].b-1,0,1,qry[i].ID};
        }
    Solve();
    //3.顺时针 90 度,上下颠倒 
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)
        {
            if(qry[i].c<2) continue;
            trg[++tnum]=msg{qry[i].b+qry[i].c-1,qry[i].a,qry[i].c-1,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{qry[i].d,qry[i].b,0,1,qry[i].ID};
            trg[++tnum]=msg{qry[i].c-1,qry[i].b,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].d,qry[i].a-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].c-1,qry[i].a-1,0,1,qry[i].ID};
        }
    Solve();
    //4.上下左右颠倒
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)
        {
            if(qry[i].c<2) continue;
            trg[++tnum]=msg{-(qry[i].a-qry[i].c+1),-(qry[i].b+1),qry[i].c-1,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{-qry[i].a,-qry[i].c,0,1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].b-1,-qry[i].c,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].a,-qry[i].d-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].b-1,-qry[i].d-1,0,1,qry[i].ID};
        }
    Solve();
    //5.左右颠倒
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1) trg[++tnum]=msg{-(qry[i].a-qry[i].c+1),qry[i].b,qry[i].c,qry[i].d,0};
        else
        {
            trg[++tnum]=msg{-qry[i].a,qry[i].d,0,1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].b-1,qry[i].d,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].a,qry[i].c-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].b-1,qry[i].c-1,0,1,qry[i].ID};
        }
    Solve();
    //6.逆时针 90 度 
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)
        {
            if(qry[i].c<2) continue;
            //(a,b-c+1)
            trg[++tnum]=msg{-(qry[i].b-qry[i].c+1),qry[i].a,qry[i].c-1,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{-qry[i].c,qry[i].b,0,1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].d-1,qry[i].b,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].c,qry[i].a-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].d-1,qry[i].a-1,0,1,qry[i].ID};
        }
    Solve();
    //7.逆时针 90 度,左右颠倒 
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)
        {
            if(qry[i].c<2) continue;
            //(a+1,b-c+1)
            trg[++tnum]=msg{-(qry[i].b-qry[i].c+1),-(qry[i].a+1),qry[i].c-1,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{-qry[i].c,-qry[i].a,0,1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].d-1,-qry[i].a,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].c,-qry[i].b-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{-qry[i].d-1,-qry[i].b-1,0,1,qry[i].ID};
        }
    Solve();
    //8.不变
    tnum=0;
    for(int i=1;i<=n;i++)
        if(qry[i].opt==1)
        {
            if(qry[i].c<2) continue;
            trg[++tnum]=msg{qry[i].a+qry[i].c-1,qry[i].b,qry[i].c-1,qry[i].d,0};
        }
        else
        {
            trg[++tnum]=msg{qry[i].b,qry[i].d,0,1,qry[i].ID};
            trg[++tnum]=msg{qry[i].a-1,qry[i].d,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].b,qry[i].c-1,0,-1,qry[i].ID};
            trg[++tnum]=msg{qry[i].a-1,qry[i].c-1,0,1,qry[i].ID};
        }
    Solve();
    for(int i=1;i<=anum;i++)
    {
        ll res=ans[i]&((1ll<<31)-1);
        res>>=1;
        printf("%lld\n",(res*715827883)&((1<<30)-1));
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5688kb

input:

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

output:

46
21

result:

ok 2 number(s): "46 21"

Test #2:

score: 0
Accepted
time: 60ms
memory: 6240kb

input:

998
2 551 711 262 646
2 128 467 106 519
1 558 927 450 66595084
1 361 809 208 60332548
1 515 957 618 80796575
2 284 931 117 684
1 896 611 247 70974392
1 11 714 426 87481360
2 881 968 136 697
1 454 562 451 86471007
1 101 439 155 51776388
2 2 672 46 246
1 524 268 227 93245818
2 223 697 669 757
1 162 72...

output:

0
0
865123352
72746388
850072396
798324882
774403614
216523785
291994372
252858880
633224401
1023164015
927266681
704934823
613223554
326574162
31121370
165845274
710425585
1008427115
478409704
774115858
81820823
1028825544
236200928
1044043263
21324351
108862558
279895600
371112374
533411993
237570...

result:

ok 504 numbers

Test #3:

score: 0
Accepted
time: 70ms
memory: 6324kb

input:

1000
2 49137835 70671601 18873956 45874590
2 62645552 74753238 40096924 44551254
1 23512931 60954680 18957528 96359308
1 44828075 13659883 84702582 21556355
2 81019283 90444820 9236193 67066200
1 76455432 68444319 69049734 71359001
1 85968266 38618636 64564140 25708147
2 71871355 83958298 82270065 8...

output:

0
0
283578221
119903392
280174084
587234423
830444436
266626034
251202955
952481576
363239411
933156865
695412350
120684074
275453831
370390065
552584676
1002405616
311611347
633585565
159628784
1052494607
307772622
1045418949
625999458
692573127
859700262
675316552
313567150
575197528
937579202
226...

result:

ok 501 numbers

Test #4:

score: 0
Accepted
time: 1850ms
memory: 15484kb

input:

20000
1 12645 2866 6360 60038699
2 8600 18135 583 6439
2 10455 12223 3170 6140
2 529 19186 6791 15927
1 19027 13358 4796 45848953
2 452 9407 783 5737
1 825 9101 3288 89339793
2 505 6673 8300 19607
1 6666 4078 768 62504799
2 29 4217 9803 17639
1 3785 1586 5932 98262710
2 14170 18816 10657 19226
1 135...

output:

649076427
948797588
398109766
155232147
1050171013
234845551
731500633
262944450
731174161
985456452
233892162
147795336
1047411174
204761351
759857964
39953660
495050735
469908224
227421565
746309996
779762035
457768132
1056781031
734873596
254189680
39933239
548847625
658668744
612765985
592063101...

result:

ok 9934 numbers

Test #5:

score: 0
Accepted
time: 2338ms
memory: 18288kb

input:

20000
1 35875808 41271162 15649261 97332439
1 60076055 10670568 46206805 4708435
1 80941697 55158038 27140631 64994669
1 81072601 37732247 67252873 95838598
2 13889716 31487760 18360212 54776354
1 64013319 52784196 1192954 26367316
2 13309550 67584319 44787440 79611197
1 94074392 1816309 59697919 14...

output:

959644379
520591272
678805150
799769290
291949562
231926815
370207939
50423944
683713972
184406145
488458300
975817382
728264554
585589401
555884719
852635213
21949908
613357018
5199310
798644890
158681267
146133482
818203446
420974202
181731921
276745474
467358724
291701152
237483093
347826791
1040...

result:

ok 9983 numbers

Test #6:

score: 0
Accepted
time: 4303ms
memory: 26140kb

input:

40000
1 24477 15043 28779 381837
2 6407 29715 3734 26742
2 21502 24741 3756 4921
2 24035 27587 10883 16422
2 4167 15193 8572 17212
2 31573 35239 13565 33543
2 10834 15825 12847 17600
1 13719 16868 17452 48868568
1 10849 5983 13723 17231005
1 25322 31268 11927 4957959
2 33389 33467 161 34981
2 27674 ...

output:

942520624
832292632
534228654
438904562
1068346239
404526720
417918862
238527871
1017668887
229430316
1051172113
236484689
295464858
359174442
610140037
709463512
938121288
766371103
238353432
106469718
297116802
505928402
203511543
193621995
128437244
748796655
426101131
303424013
659843159
4089861...

result:

ok 19894 numbers

Test #7:

score: 0
Accepted
time: 5442ms
memory: 29016kb

input:

39996
2 14398076 47189365 25223993 32485788
1 27404693 23456287 55354605 76894669
2 12718401 99241315 6986342 42231497
1 26939327 4572122 39427634 38908170
2 8541583 12741036 61299 68911467
2 57381301 99213031 17399196 23972914
1 19243565 65499724 35495025 1875339
1 60573965 95550457 49508796 816574...

output:

0
1023384377
535237129
966847501
431567368
480423347
493135712
55586415
453728552
9196285
877756005
612079740
826695744
513854135
309218300
117613646
962155971
154976262
106291611
991802214
321154632
879250687
823779625
488895704
65601581
336190911
13156163
285363313
958869547
925631647
347129146
10...

result:

ok 19837 numbers

Test #8:

score: 0
Accepted
time: 7028ms
memory: 36152kb

input:

60000
2 1244 25287 1116 40310
1 28643 43078 9088 64014005
1 21653 7613 58290 49776046
1 27897 27965 57716 51238467
2 27957 42988 14033 37349
2 35178 38145 18010 41957
2 13455 30014 24744 34418
2 52745 56844 32461 53197
1 12812 2194 28203 84445563
1 17389 21680 3251 65393869
1 21226 6499 21189 261941...

output:

0
867152932
506363671
544065420
424565186
328219495
968765637
545575429
533102406
414318336
437873626
462003967
990157221
791816093
351869684
102865090
16258317
123255150
177831311
937868926
1000441411
60689323
742106254
473428287
990157869
760105960
755562381
272476566
797108514
147385751
716643120...

result:

ok 29952 numbers

Test #9:

score: 0
Accepted
time: 9086ms
memory: 38996kb

input:

60000
1 98378453 54382890 45176081 59520425
1 33986858 83703947 92586675 5398466
2 5970804 93121855 978357 68083043
2 21728231 63957955 9235536 16021368
1 82626059 10489401 75610240 80170176
2 48539084 79694254 34828432 92785760
2 71094153 86043819 4331292 73343754
1 89675821 16878006 23920520 63715...

output:

646438944
500894480
911202059
417069480
81528438
480895104
232330822
870766304
473193107
930581740
94244303
133205960
982567214
19107930
748983217
403172993
948951065
509505894
454439423
468364554
235287395
409946414
423142358
620909328
523200586
295320790
890455712
393989387
12384303
44886632
52516...

result:

ok 29870 numbers

Test #10:

score: 0
Accepted
time: 9953ms
memory: 45664kb

input:

79997
2 19778 25444 8100 61577
2 4574 24766 12981 14024
1 69341 70212 18311 15650930
2 10892 15120 32290 55142
1 36553 7664 38320 1288519
1 6872 25148 10772 97851181
1 27537 71318 23522 26962551
1 67940 7793 56125 4467657
1 77525 35799 78383 52467566
1 11284 77961 9681 20103911
2 47441 61710 30379 7...

output:

0
0
0
567184258
565003013
562478264
179874432
303219712
920631814
352920370
510309774
491583906
218691060
251542939
92510518
1070657194
478707142
433167012
437017048
805395186
813728481
1027906179
341479493
908764813
681531408
565829393
917720019
941826337
879790869
603348263
745259514
215549470
343...

result:

ok 39999 numbers

Test #11:

score: 0
Accepted
time: 13349ms
memory: 50168kb

input:

79997
1 36696271 41216261 96326194 62696256
2 19810443 52576336 262983 53774996
1 97666207 4432633 35889233 42146442
1 81532281 55149059 42520921 57325424
2 12122185 89775406 52099353 55361961
2 563070 36509043 96726240 96854363
1 26431754 48604940 2981416 49044638
2 49491178 97195825 47480140 91181...

output:

61574144
185869392
174584576
302599040
765518428
452330918
192548356
947873571
514727486
1068708423
439751319
633268755
969643203
235187384
750411187
451005249
605712013
257223298
582921046
197813999
1043015301
529116764
309667986
877519643
988474139
804279112
432291138
946341401
924454707
828761623...

result:

ok 40069 numbers

Test #12:

score: 0
Accepted
time: 11664ms
memory: 52696kb

input:

100000
1 34380 11421 6894 5421501
1 14317 42540 9268 76794286
1 24981 27368 32903 80438213
1 19432 85459 45142 91474294
1 36996 66026 42309 84168947
1 94561 54868 62797 6492386
1 43237 84001 20645 65733571
1 50054 74924 2714 72370240
1 33891 57907 76375 2662996
1 73360 18612 73561 59515230
1 74114 7...

output:

148876392
961410585
419839061
141672616
121996678
102979758
1025962479
555097376
200804515
613812385
805960503
73778093
80100787
275869683
601941514
149124890
869355373
311993802
423760390
499922791
709093821
754861967
338701217
604004520
166235232
60767414
255270250
370488815
1030265672
232402411
6...

result:

ok 50000 numbers

Test #13:

score: 0
Accepted
time: 13106ms
memory: 50028kb

input:

100000
1 33530298 1200235 32300428 21036259
1 90929480 41868440 70071824 79921886
1 94836015 74305971 92763837 32401800
1 78818280 30839372 84264497 62051402
1 48477131 30560030 639775 10073178
1 42166977 65863007 39554976 87495793
1 67356181 47808477 80716790 32207885
1 73456961 88772936 82465051 2...

output:

832214329
158835942
828195654
42699425
1011101117
403691743
890075196
227362193
749630070
587629877
725362293
321338449
910032482
705896517
19637806
626069255
840720379
257763227
1000157334
182911450
713926675
724299559
607900440
1032365109
364821448
227254038
985435706
502400153
675887222
966888194...

result:

ok 20326 numbers

Test #14:

score: 0
Accepted
time: 10732ms
memory: 54304kb

input:

99998
2 60156 60161 73255 73260
2 74890 74895 16915 16920
2 86184 86189 53538 53543
2 94635 94640 45305 45310
2 46788 46793 46995 47000
2 56664 56669 63605 63610
1 61984 89188 2 38368837
2 66407 66412 95069 95074
2 50982 50987 30601 30606
2 75820 75825 91943 91948
1 70827 90425 5 36463542
2 69287 69...

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 49708 numbers

Test #15:

score: 0
Accepted
time: 12679ms
memory: 61380kb

input:

100000
1 86436691 6108307 3 53041518
2 55197814 55197819 58054356 58054361
2 43151707 43151712 98934930 98934935
1 28934640 2328977 4 2373200
2 64805939 64805944 95487216 95487221
2 66902152 66902157 99157483 99157488
2 54671122 54671127 91291299 91291304
2 60859348 60859353 70878593 70878598
1 8434...

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 49989 numbers

Test #16:

score: 0
Accepted
time: 12207ms
memory: 54792kb

input:

99996
1 11500 1524 5 10014694
1 95816 72482 5 10140174
1 12358 21555 5 58438000
2 13281 35573 7833 9556
2 29575 44915 39972 61032
2 48961 76713 54659 84942
1 12505 1046 5 59961488
2 39117 92428 44528 52757
1 41493 57978 5 735953
1 49893 65640 5 20431787
2 44314 93165 363 50633
2 83728 95770 38078 78...

output:

0
0
0
0
0
0
0
894411802
103924520
894900226
103924520
0
121432245
143327085
271451628
1002815938
0
262050874
0
78537612
544727156
0
0
0
740218108
440585
558086037
345678372
37503289
524823800
121432245
427192286
0
1047860448
402873167
100437840
649634054
810525035
0
555410358
150019383
0
1020957119
...

result:

ok 50077 numbers

Test #17:

score: 0
Accepted
time: 16131ms
memory: 62936kb

input:

99995
1 72131666 12334058 5 34265674
2 11863282 97072975 72626352 90833011
1 31981854 47799985 2 5266163
2 49016880 59235746 6819244 18682811
1 55699971 3191506 4 3470511
1 39383413 45308224 5 66538067
1 18076832 7347410 4 72246600
2 2426337 54162184 613949 60765314
2 23018906 78886521 74070057 8006...

output:

0
0
994029725
0
0
0
0
0
677110257
146870170
0
0
823980427
677110257
0
0
0
639016043
385385768
657600989
626748583
968676622
0
677110257
0
0
294024445
0
181649103
388291089
76220771
146870170
360476996
826169906
23241557
1032812637
350974358
822585773
134011751
0
21231581
0
350974358
604354516
0
4940...

result:

ok 49816 numbers

Test #18:

score: 0
Accepted
time: 12919ms
memory: 57172kb

input:

100000
1 3852 55739 98740 96211606
1 30204 8583 6739 69713251
2 18698 73644 57103 97611
2 64459 73969 2309 10342
2 19039 52338 20689 37499
1 3500 25338 72549 12736124
2 25057 29166 63599 81163
2 26634 57184 4493 78479
1 42976 66205 67971 40409393
2 77850 93993 32109 55238
1 17647 64780 89003 8973547...

output:

837284522
907079272
957593004
1013123768
413315843
559718096
469224949
269276365
730104495
515905984
704620230
634149640
520149089
15280064
72940269
108516865
854999906
229229979
518651515
149799289
899063715
502076504
469547118
957072927
389085487
107438668
925418973
857736589
593123400
304374432
9...

result:

ok 50088 numbers

Test #19:

score: 0
Accepted
time: 17870ms
memory: 65144kb

input:

100000
2 31074951 52328678 46926364 74309944
1 65226742 66402750 67441739 47235396
2 2751124 47213164 19878396 44911725
2 70943708 95737950 5935487 39364772
1 33996961 93533623 8662969 90069972
2 52436199 99095174 86229296 93221180
2 5042501 52974285 1860599 46027420
2 66016129 67588602 50202859 561...

output:

0
779360104
890218708
285795428
451307612
684935272
218232434
130553196
245698666
1034654856
857003514
854269169
521066624
629250333
571222758
799039191
22368757
469949920
145387007
457410491
425555305
983064205
810216570
331629952
243291224
739676817
627349941
759164920
197945379
641163157
71374732...

result:

ok 50103 numbers

Test #20:

score: 0
Accepted
time: 3ms
memory: 7616kb

input:

1
1 1 1 1 1

output:


result:

ok 0 number(s): ""

Test #21:

score: 0
Accepted
time: 2ms
memory: 18176kb

input:

1
2 1 1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 2ms
memory: 18080kb

input:

2
2 1 1 1 1
1 1 1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 3276ms
memory: 39776kb

input:

100000
1 99999992 100000000 99999990 99999999
1 99999993 100000000 99999998 99999994
1 99999998 99999995 99999999 100000000
1 99999995 99999991 99999994 99999997
1 99999992 99999990 100000000 99999996
1 99999998 100000000 99999990 99999990
1 99999999 99999990 99999992 99999999
1 99999997 99999993 10...

output:

898153686
908753639
575940149
905570939
97509622
891946487
545601006
1013368397
763405628
99157101
325230094
1028554564
787066555
833244742
771963643
562235831
755583279
906657062
487111315
817791150
844489054
447509894
75009384
69962446
175505088
465467452
282743241
251020240
48748040
392777579
514...

result:

ok 5000 numbers

Test #24:

score: 0
Accepted
time: 5994ms
memory: 63524kb

input:

100000
2 99999997 99999997 99999994 99999998
2 99999995 99999998 99999995 100000000
2 99999992 99999996 99999997 99999998
2 99999993 99999999 99999998 100000000
2 99999997 99999999 99999996 99999997
2 99999994 99999998 99999999 99999999
2 99999994 99999998 99999990 99999991
2 99999992 99999995 99999...

output:

0
0
0
0
0
0
0
0
314342893
309632433
256260605
33857368
761293069
681341091
752194178
578452309
78452334
1049911398
306071026
449560837
343167772
896539575
707599212
651016568
209632438
352194198
275775065
563398745
282591295
191295513
573170184
260649204
734713019
225364529
830324415
277559030
28219...

result:

ok 95000 numbers

Test #25:

score: 0
Accepted
time: 3038ms
memory: 39044kb

input:

100000
1 99999995 99999998 99999993 99999992
1 99999997 99999999 100000000 99999990
1 99999992 99999998 99999993 99999993
1 99999993 100000000 99999995 100000000
1 100000000 99999993 99999990 99999997
1 99999994 99999995 99999994 99999995
1 99999994 99999995 99999999 99999994
1 99999990 99999994 999...

output:

638331431

result:

ok 1 number(s): "638331431"

Test #26:

score: 0
Accepted
time: 5906ms
memory: 62856kb

input:

100000
2 99999994 99999998 99999990 99999995
2 99999990 99999999 99999998 100000000
2 99999992 99999999 99999994 99999996
2 99999990 99999993 99999991 99999992
2 99999995 99999997 99999993 99999993
2 99999994 99999999 99999992 99999994
2 99999994 99999997 99999995 99999996
2 99999993 99999995 999999...

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 99999 numbers