QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113127#5686. 种苹果myeeAC ✓5395ms84860kbC++1111.3kb2023-06-16 14:50:292023-06-16 14:50:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-16 14:50:32]
  • 评测
  • 测评结果:AC
  • 用时:5395ms
  • 内存:84860kb
  • [2023-06-16 14:50:29]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

// 不弱于教主的魔法,可以规约矩阵乘法,考虑根号。
// 根号重构 + 树剖分块。
// 维护添加点的联通块。
// 每次重构把当前树重新剖分,进行信息的更新。
// 然后两类加点操作可以“新开联通块”或者“联通块内重构结构”。(广义串并联图的方式?)
// 加权操作可以对整颗树上加,各个联通块内的点依次判断是否在修改链上,暴力修改即可。
// 查询操作可以树上使用树剖分块查询,额外点也查询。
// 总复杂度 O(n\sqrt{n\log n}) (n\sim q)

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
const uint Block=640,Lim=400000;
uint Siz[Lim+5],Heavy[Lim+5],Fath[Lim+5],Rot[Lim+5],Dep[Lim+5],Dfn[Lim+5],End[Lim+5],Back[Lim+5],n,tp;
llt Val[Lim+5],Tag[Lim/Block+5];bol Gone[Lim+5];
std::pair<llt,uint>W[Lim/Block+5][Block+5];uint WCnt[Lim/Block+5];
std::vector<uint>Way[Lim+5],Del[Lim+5];
voi dfs1(uint p,uint f){
    Fath[p]=f,Heavy[p]=-1,Siz[p]=1;
    for(auto s:Way[p])if(s!=f){
        Dep[s]=Dep[p]+1,dfs1(s,p),Siz[p]+=Siz[s];
        if(!~Heavy[p]||Siz[s]>Siz[Heavy[p]])Heavy[p]=s;
    }
}
voi dfs2(uint p,uint r){
    Back[Dfn[p]=tp++]=p,Rot[p]=r;if(~Heavy[p])dfs2(Heavy[p],r);
    for(auto s:Way[p])if(s!=Fath[p]&&s!=Heavy[p])dfs2(s,s);
    End[p]=tp;
}
voi rebuild(){
    if(n&&tp-n<2400)return;
    for(uint i=0;i<=n/Block;i++)for(uint j=0;j<WCnt[i];j++)Val[Back[W[i][j].second]]=W[i][j].first+Tag[i];
    for(uint i=0;i<n;i++)if(Del[i].size()){
        std::sort(Del[i].begin(),Del[i].end());
        for(uint j=0,t=0;j<Way[i].size();j++)
            if(t==Del[i].size()||Del[i][t]!=Way[i][j])Way[i][j-t]=Way[i][j];else t++;
        Way[i].resize(Way[i].size()-Del[i].size()),Del[i].clear();
    }
    for(uint i=n;i<tp;i++){std::sort(Way[i].begin(),Way[i].end());for(auto s:Way[i])if(s<n)Way[s].push_back(i);}
    n=tp,tp=0,dfs1(0,-1),dfs2(0,0);
    for(uint i=0;i<=n/Block;i++){
        WCnt[i]=0,Tag[i]=0;
        for(uint j=i*Block;j<(i+1)*Block&&j<n;j++)W[i][WCnt[i]++]={Val[Back[j]],j};
        std::sort(W[i],W[i]+WCnt[i]);
    }
}
voi add_dfn(uint l,uint r,llt w){
    if(l>=r)return;
    std::vector<std::pair<llt,uint> >A,B;
    if(l/Block==r/Block){
        for(uint i=0;i<WCnt[l/Block];i++)if(W[l/Block][i].second>=l&&W[l/Block][i].second<r)
            A.push_back({W[l/Block][i].first+w,W[l/Block][i].second});else B.push_back(W[l/Block][i]);
        std::merge(A.begin(),A.end(),B.begin(),B.end(),W[l/Block]);
        return;
    }
    for(uint i=0;i<WCnt[l/Block];i++)if(W[l/Block][i].second>=l)
        A.push_back({W[l/Block][i].first+w,W[l/Block][i].second});else B.push_back(W[l/Block][i]);
    std::merge(A.begin(),A.end(),B.begin(),B.end(),W[l/Block]);
    A.clear(),B.clear();
    for(uint i=0;i<WCnt[r/Block];i++)if(W[r/Block][i].second<r)
        A.push_back({W[r/Block][i].first+w,W[r/Block][i].second});else B.push_back(W[r/Block][i]);
    std::merge(A.begin(),A.end(),B.begin(),B.end(),W[r/Block]);
    for(uint i=l/Block+1;i<r/Block;i++)Tag[i]+=w;
}
uint query_dfn(uint l,uint r,llt w){
    if(l>=r)return 0;
    uint ans=0;
    if(l/Block==r/Block){
        for(uint i=WCnt[l/Block]-1;~i&&W[l/Block][i].first+Tag[l/Block]>=w;i--)
            if(W[l/Block][i].second>=l&&W[l/Block][i].second<r)ans++;
        return ans;
    }
    for(uint i=WCnt[l/Block]-1;~i&&W[l/Block][i].first+Tag[l/Block]>=w;i--)
        if(W[l/Block][i].second>=l)ans++;
    for(uint i=WCnt[r/Block]-1;~i&&W[r/Block][i].first+Tag[r/Block]>=w;i--)
        if(W[r/Block][i].second<r)ans++;
    for(uint i=l/Block+1;i<r/Block;i++)if(WCnt[i]){
        if(W[i][0].first+Tag[i]>=w)ans+=WCnt[i];
        else if(W[i][WCnt[i]-1].first+Tag[i]>=w){
            uint l=0,r=WCnt[i],mid;
            while(l<r)if(W[i][mid=(l+r)>>1].first+Tag[i]>=w)r=mid;else l=mid+1;
            ans+=WCnt[i]-l;
        }
    }
    return ans;
}
uint lca(uint u,uint v){
    while(Rot[u]!=Rot[v]){
        if(Dep[Rot[u]]<Dep[Rot[v]])std::swap(u,v);
        u=Fath[Rot[u]];
    }
    return Dep[u]<Dep[v]?u:v;
}
bol OnWay(uint u,uint v,uint p){
    while(Rot[u]!=Rot[v]){
        if(Dep[Rot[u]]<Dep[Rot[v]])std::swap(u,v);
        if(Dfn[p]>Dfn[u]&&Dfn[p]>Dfn[v])return 0;
        if(Dfn[p]>=Dfn[Rot[u]]&&Dfn[p]<=Dfn[u])return 1;
        u=Fath[Rot[u]];
    }
    if(Dep[u]>Dep[v])std::swap(u,v);
    return Dfn[p]>=Dfn[u]&&Dfn[p]<=Dfn[v];
}
bol OnWay(uint u,uint v,uint r,uint p){
    return p==r||(Dfn[u]>=Dfn[p]&&Dfn[u]<End[p])!=(Dfn[v]>=Dfn[p]&&Dfn[v]<End[p]);
}
voi add_line(uint u,uint v,llt w){
    while(Rot[u]!=Rot[v]){
        if(Dep[Rot[u]]<Dep[Rot[v]])std::swap(u,v);
        add_dfn(Dfn[Rot[u]],Dfn[u]+1,w),u=Fath[Rot[u]];
    }
    if(Dep[u]>Dep[v])std::swap(u,v);
    add_dfn(Dfn[u],Dfn[v]+1,w);
}
uint query_line(uint u,uint v,llt w){
    uint ans=0;
    while(Rot[u]!=Rot[v]){
        if(Dep[Rot[u]]<Dep[Rot[v]])std::swap(u,v);
        ans+=query_dfn(Dfn[Rot[u]],Dfn[u]+1,w),u=Fath[Rot[u]];
    }
    if(Dep[u]>Dep[v])std::swap(u,v);
    ans+=query_dfn(Dfn[u],Dfn[v]+1,w);
    return ans;
}
std::vector<uint>V,PSet;
bol dfs(uint p,uint f,uint t){
    V.push_back(p);
    if(p==t)return 1;
    for(auto s:Way[p])if(s>=n&&s!=f&&dfs(s,p,t))return 1;
    V.pop_back();
    return 0;
}
voi add(uint u,uint v,llt w){
    V.clear();
    for(uint i=n;i<tp;i++)Gone[i]=0;
    if(u>=n&&v<n)std::swap(u,v);
    if(v>=n){
        if(u<n){
            std::vector<std::pair<uint,uint> >P;
            PSet={v};Gone[v]=1;
            while(PSet.size()){
                uint p=PSet.back();PSet.pop_back();
                for(auto s:Way[p])if(s<n)P.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
            }
            bol op=P.size()==1?0:OnWay(u,P[0].second,P[1].second);
            dfs(P[op].first,-1u,v),v=P[op].second;
        }
        else{
            std::vector<std::pair<uint,uint> >P1,P2;
            PSet={u};Gone[u]=1;
            while(PSet.size()){
                uint p=PSet.back();PSet.pop_back();
                for(auto s:Way[p])if(s<n)P1.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
            }
            if(Gone[v]){
                dfs(u,-1,v);for(auto s:V)Val[s]+=w;
                return;
            }
            PSet={v};Gone[v]=1;
            while(PSet.size()){
                uint p=PSet.back();PSet.pop_back();
                for(auto s:Way[p])if(s<n)P2.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
            }
            bol op1=P1.size()==1?0:OnWay(P1[0].second,P2[0].second,P1[1].second);
            bol op2=P2.size()==1?0:OnWay(P1[0].second,P2[0].second,P2[1].second);
            dfs(P1[op1].first,-1u,u),dfs(P2[op2].first,-1u,v),u=P1[op1].second,v=P2[op2].second;
        }
    }
    add_line(u,v,w);
    uint r=lca(u,v);
    for(uint i=n;i<tp;i++)if(!Gone[i]){
        std::vector<std::pair<uint,uint> >P;
        PSet={i},Gone[i]=1;
        while(PSet.size()){
            uint p=PSet.back();PSet.pop_back();
            for(auto s:Way[p])if(s<n)P.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
        }
        if(P.size()==2&&OnWay(u,v,r,P[0].second)&&OnWay(u,v,r,P[1].second))dfs(P[0].first,-1u,P[1].first);
    }
    for(auto s:V)Val[s]+=w;
}
uint query(uint u,uint v,llt w){
    V.clear();
    uint ans=0;for(uint i=n;i<tp;i++)Gone[i]=0;
    if(u>=n&&v<n)std::swap(u,v);
    if(v>=n){
        if(u<n){
            std::vector<std::pair<uint,uint> >P;
            PSet={v};Gone[v]=1;
            while(PSet.size()){
                uint p=PSet.back();PSet.pop_back();
                for(auto s:Way[p])if(s<n)P.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
            }
            bol op=P.size()==1?0:OnWay(u,P[0].second,P[1].second);
            dfs(P[op].first,-1u,v);
            v=P[op].second;
        }
        else{
            std::vector<std::pair<uint,uint> >P1,P2;
            PSet={u};Gone[u]=1;
            while(PSet.size()){
                uint p=PSet.back();PSet.pop_back();
                for(auto s:Way[p])if(s<n)P1.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
            }
            if(Gone[v]){
                dfs(u,-1,v);for(auto s:V)ans+=Val[s]>=w;
                return ans;
            }
            PSet={v};Gone[v]=1;
            while(PSet.size()){
                uint p=PSet.back();PSet.pop_back();
                for(auto s:Way[p])if(s<n)P2.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
            }
            bol op1=P1.size()==1?0:OnWay(P1[0].second,P2[0].second,P1[1].second);
            bol op2=P2.size()==1?0:OnWay(P1[0].second,P2[0].second,P2[1].second);
            dfs(P1[op1].first,-1u,u),dfs(P2[op2].first,-1u,v),u=P1[op1].second,v=P2[op2].second;
        }
    }
    ans+=query_line(u,v,w);
    uint r=lca(u,v);
    for(uint i=n;i<tp;i++)if(!Gone[i]){
        std::vector<std::pair<uint,uint> >P;
        PSet={i};Gone[i]=1;
        while(PSet.size()){
            uint p=PSet.back();PSet.pop_back();
            for(auto s:Way[p])if(s<n)P.push_back({p,s});else if(!Gone[s])Gone[s]=1,PSet.push_back(s);
        }
        if(P.size()==2&&OnWay(u,v,r,P[0].second)&&OnWay(u,v,r,P[1].second))dfs(P[0].first,-1u,P[1].first);
    }
    for(auto s:V)ans+=Val[s]>=w;
    return ans;
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    uint q,ans=0;scanf("%u%u",&tp,&q);
    for(uint i=0;i<tp;i++)scanf("%lld",Val+i);
    for(uint i=1,u,v;i<tp;i++)scanf("%u%u",&u,&v),Way[--u].push_back(--v),Way[v].push_back(u);
    while(q--){
        rebuild();
        uint op,u,v;int w;
        scanf("%u%u",&op,&u),u=(u^ans)-1;
        if(op==1){
            scanf("%u%d",&v,&w),v=(v^ans)-1,w^=ans,Val[tp]=w;
            if(u>=n&&v<n)std::swap(u,v);
            if(u<n&&v<n)Del[u].push_back(v),Del[v].push_back(u);
            else if(u<n){for(auto&s:Way[v])if(s==u)s=tp;}
            else{
                for(auto&s:Way[v])if(s==u)s=tp;
                for(auto&s:Way[u])if(s==v)s=tp;
            }
            Way[tp++]={u,v};
        }else if(op==2){
            scanf("%d",&w),w^=ans,Val[tp]=w;
            if(u>=n)Way[u].push_back(tp);
            Way[tp++].push_back(u);
        }
        else if(op==3)scanf("%u%d",&v,&w),v=(v^ans)-1,w^=ans,add(u,v,w);
        else scanf("%u%d",&v,&w),v=(v^ans)-1,w^=ans,printf("%u\n",ans=query(u,v,w));
    }
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

详细

Test #1:

score: 100
Accepted
time: 76ms
memory: 35764kb

input:

5000 5000
-1201801 4507224 -765313 5795451 -126649 -5052948 470601 -5571705 7680665 -2662502 -689392 -3195719 3416253 -1023134 -3112032 3810606 -6975732 712075 257599 -180764 5190759 177433 -6055975 1555412 7768627 3402404 -872471 -1311920 -4231370 117735 3172664 -1502849 -3929398 -90435 6955032 382...

output:

645
0
0
0
57
0
1665
1087
1455
73
1172
1094
0
1739
1202
1290
0
0
0
569
0
1532
0
358
337
437
0
567
1086
12
73
922
1024
183
25
0
0
0
979
4
3
7
162
305
1285
0
1185
0
1263
402
576
1284
0
0
832
908
0
422
1425
1268
12
0
1692
439
0
0
28
0
384
0
0
1079
1257
1149
541
642
133
966
406
0
0
848
1335
431
0
0
363
8...

result:

ok 1020 lines

Test #2:

score: 0
Accepted
time: 88ms
memory: 37152kb

input:

5000 5000
-994733 862196 -2643618 4810652 2000445 -712322 -3955371 2924820 -675771 -6848147 825176 -5612153 4757907 1475460 1043402 1647007 -1015110 2001651 -6330733 2969460 -815149 6241724 136943 2360333 -3204656 5569099 809569 -4081554 -178998 -1363975 -4486956 -1858705 -59824 845830 4381332 17942...

output:

1469
2442
2
0
35
1869
0
353
993
1572
1095
0
12
1458
0
1659
545
0
0
1243
0
0
1410
911
1701
1660
0
0
84
728
0
5
0
1031
2089
1108
524
225
1237
2233
3
43
1324
327
1085
1049
615
61
1840
1892
0
491
989
242
1058
965
625
0
2592
340
36
0
211
0
146
2168
46
0
227
0
0
0
8
2103
1334
0
23
128
0
0
1307
0
0
0
2280
...

result:

ok 962 lines

Test #3:

score: 0
Accepted
time: 83ms
memory: 36656kb

input:

5000 5000
1655881 -6171013 -6563069 6407036 -349214 1212406 2942912 -6594577 2008815 -1128329 -2115530 3807690 2938269 3705147 -5102093 -5658055 -2326373 4349357 -299635 825659 877457 3662152 358404 -892346 4685730 5257128 -6518733 -852709 4390588 -3492594 4680660 -386634 1743811 4770445 1735641 -39...

output:

1263
2159
0
107
4
2257
15
1329
172
0
929
0
1465
260
2106
496
685
80
347
1492
0
2638
409
0
177
0
0
0
5
0
2324
0
179
0
0
0
2122
1322
102
412
300
3
1272
0
6
0
1823
0
13
1739
1459
13
1207
278
0
1261
0
684
0
284
639
69
1700
88
243
1529
1970
0
98
2178
0
978
0
1229
1637
1620
660
835
0
0
214
953
203
674
159...

result:

ok 1055 lines

Test #4:

score: 0
Accepted
time: 82ms
memory: 35788kb

input:

5000 5000
1916330 -1277666 -2692038 -1686680 445447 522240 -9102533 4958411 5497747 -6470449 -1304451 -327692 -3951014 -5481922 -71181 -324109 -2416764 -6133434 -2713206 -6507719 -4562989 3531489 2232499 -1303696 3799685 1596321 4508356 -698966 6244189 -3451377 1146222 -1190263 -1224078 -1867687 256...

output:

0
0
0
1099
0
463
0
1182
25
0
784
0
663
1483
2171
0
1057
0
0
1377
0
0
0
218
0
0
70
906
1524
141
89
992
0
1667
0
308
0
77
6
0
148
0
1364
121
513
162
0
1440
1
1588
290
0
380
0
1517
8
1125
0
1362
592
74
0
83
443
857
0
0
0
10
307
1182
6
2352
15
953
31
966
2
536
2104
872
347
0
1846
185
146
1096
0
368
295
...

result:

ok 1023 lines

Test #5:

score: 0
Accepted
time: 797ms
memory: 53300kb

input:

200000 200000
3962736 -7195878 -1853269 5312599 2123365 7028251 2312158 123258 -4443494 -5269322 877331 -616200 927434 -1927540 2943960 -7002528 -5869789 2362131 -2612652 -7859698 2076672 3520022 5147597 17824 -54033 5931665 -8193552 4202786 2726128 1137312 5233018 -580693 2414120 4925088 1642992 35...

output:

47152
78705
47731
29708
99910
0
62117
0
44783
61200
5955
2
46232
0
16545
1271
36509
0
90957
1856
0
84922
27751
45838
0
91943
2373
28623
1118
32482
0
3
63630
57801
81142
0
0
0
9458
0
34391
12206
9510
0
0
1284
92189
98017
23372
7
4783
38278
54827
0
0
0
65641
0
13882
16443
908
0
59951
44221
36623
0
897...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 799ms
memory: 53072kb

input:

200000 200000
-268518 -732548 -901441 -4347722 -192409 4152660 -6078366 -412851 3364009 7704344 323003 -4336546 -1823880 -1675134 -4301206 1362880 -2495946 -7053206 -2570038 2259491 2394744 3832046 -4643805 2294419 -4484291 -7340794 382437 -1938061 4410387 2978726 52156 1753151 -7547313 -5689937 446...

output:

93379
79180
42500
0
34745
0
32820
0
79663
48221
0
3335
12767
0
0
45995
19496
58837
49719
0
642
887
72
0
0
22859
0
0
36154
19833
36991
990
75878
16314
0
21002
50417
81747
39036
34391
65298
0
0
32698
25301
0
39844
14215
8613
23554
79650
4124
25410
8590
60811
0
20040
0
0
52949
308
0
0
61800
22062
45239...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 806ms
memory: 52580kb

input:

200000 200000
4471605 -2889587 2475793 4794555 5897977 866381 2062774 3733737 -2810691 -3123275 -1593937 543221 -3462221 6330012 -4003863 6366641 2045393 1616425 -6199720 8342761 -855613 -5496332 2625258 -1455774 -6907661 -3748453 -831288 1686462 -5278073 3138676 5730165 2039292 694348 -1314529 -173...

output:

0
421
0
0
9681
7022
7214
0
0
27527
0
31966
0
3457
68018
29401
0
0
55150
3666
3275
1874
30536
0
12447
41
35035
12705
0
5
13675
12373
0
0
52061
77962
1654
0
0
41006
6436
0
3624
3567
35984
66500
70
32054
0
21039
12570
0
0
0
19152
70428
12137
42842
0
0
0
2763
0
38788
43503
52273
6312
12519
86158
39300
0...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 818ms
memory: 52704kb

input:

200000 200000
-890750 -1886888 4557806 -644020 494194 -2695808 2550714 4029509 1120191 -1432068 4947569 -861074 -5012051 3130809 5048423 2911722 3555406 -4902160 6599828 -5543160 4984807 -184407 -3457542 -7797283 -1069734 1904721 5103428 1063345 3476923 -1785030 4855156 -57227 -5334995 -2809093 2892...

output:

2
0
0
3040
0
28031
83220
20474
0
0
0
50236
95642
0
0
8070
0
117
0
893
2792
0
34697
79143
62228
47204
21758
0
30780
86096
5630
0
0
5183
0
30315
2222
21205
0
15214
24683
0
42490
11122
16553
0
19432
33366
0
28181
76378
13080
95166
4137
56659
2718
0
23634
16356
0
22985
42488
0
7949
0
44522
5532
0
6735
1...

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 3600ms
memory: 64256kb

input:

200000 200000
-3731977 -2214890 -2655693 -4636219 1477879 -6652495 -6122932 -2086233 195642 -707975 -1089540 3930278 524808 653005 7012999 -4338192 -7000512 -4443331 338552 2677375 -9308411 -1663420 3989374 5517790 405209 -2349520 4825993 8728231 4180825 -762268 -5023792 -1018659 -4224802 4763633 -6...

output:

5229
34782
25115
2661
50096
0
39612
26827
0
28126
2078
0
0
34407
9531
0
0
20761
0
0
47962
9851
369
0
120138
0
2
93381
0
2660
26702
47790
0
0
26704
26895
81137
0
3679
0
45393
0
14777
41981
0
7090
71613
6156
20774
3562
0
282
655
7528
15837
3
29871
0
40192
28220
0
12640
0
0
0
0
50855
47380
1280
1829
39...

result:

ok 79940 lines

Test #10:

score: 0
Accepted
time: 3623ms
memory: 63724kb

input:

200000 200000
-40585 5100748 -7038081 1817391 1576827 5519684 1368666 4000857 -5019756 -494980 -2910690 -2921575 -1450894 4525332 2493608 587091 99422 3623730 949863 6943763 -4357327 -487234 193966 -3268630 233249 -9015969 -3500159 754246 -4918832 5886202 -713657 -1322141 112522 2407975 -2746873 -34...

output:

1353
0
0
209
0
0
16009
0
68984
117993
0
0
32215
68957
7843
0
0
337
73410
79683
14844
39
0
0
0
0
76874
0
25714
26698
0
38289
28839
86
49285
66274
60145
82238
0
39904
4
92114
9631
0
0
62293
8303
17952
82285
43896
22450
91265
0
0
0
55326
0
105788
15463
0
0
18382
23669
10732
0
100590
72128
105022
90996
...

result:

ok 79866 lines

Test #11:

score: 0
Accepted
time: 3574ms
memory: 65192kb

input:

200000 200000
-6113558 -5036394 7148216 6044286 1697972 -6261572 3196523 3345060 -286718 4103655 2590674 1667153 -4959092 -3950169 -2182382 -8223477 1542982 -8047223 -7405525 4648848 5070967 1656133 1203472 3343385 -7198801 -146934 3973197 -4115776 -685357 -3235680 458167 2397624 952393 -204466 6931...

output:

0
24700
0
0
20008
1966
62996
8367
60130
0
0
2
95563
0
0
52338
0
74984
0
44896
34982
38
52382
28147
0
1266
73006
0
3202
76011
73062
0
0
28518
0
6213
58369
1657
58891
0
0
57142
45478
24232
0
10783
0
37289
1214
0
61560
4422
23841
0
0
36444
59027
0
25949
14169
31928
6282
9668
64811
0
23074
84294
0
0
684...

result:

ok 79725 lines

Test #12:

score: 0
Accepted
time: 3588ms
memory: 64360kb

input:

200000 200000
-667019 3018428 617797 -513689 -4282503 2994016 199404 -548441 -9274627 -2760620 -3651286 8292075 -2556026 486189 1385575 -1696494 -331935 1997950 -521500 -953572 -223275 1658925 2092325 -6299249 -4340122 -3655956 2451585 1658576 1975826 7018293 -2439494 6477429 1250658 -3615349 266699...

output:

5
30050
0
0
64
43951
880
0
22989
86029
21880
17179
0
79761
6470
34232
5328
0
25318
9186
0
8396
19620
26638
17256
30875
0
3240
5253
86287
0
10585
9352
9200
4
17394
0
0
4
65427
19215
1177
36090
0
80250
0
0
79412
124148
0
43081
35212
48062
23736
18349
0
100011
1470
77104
46860
1989
0
4408
0
6559
0
9074...

result:

ok 79617 lines

Test #13:

score: 0
Accepted
time: 3603ms
memory: 59860kb

input:

200000 200000
1985164 309525 -2073939 5502869 -6074995 -7109331 -2645057 2635849 -647019 4959815 -7583310 1399462 -291124 -252462 -1985823 2255567 -6571018 -5537170 -125160 -1703040 -6965276 -3922287 -2504039 4762424 -906237 -2828723 565209 1381511 1060297 2834184 -5487607 9228972 -3224921 -2327543 ...

output:

99921
0
0
8019
88
1809
0
31208
15465
0
0
0
1401
0
0
30569
30174
33756
0
0
2750
0
0
3688
69265
88946
46964
0
61957
30471
0
4
11266
0
0
0
0
0
9422
0
0
66396
0
14741
23582
40014
31318
0
0
1083
0
0
61515
49064
16358
523
0
38748
38290
180
67271
52391
54610
88425
0
26072
2993
0
3
0
84480
0
221
81985
49641...

result:

ok 59876 lines

Test #14:

score: 0
Accepted
time: 3636ms
memory: 62892kb

input:

200000 200000
4875614 -2562679 -595766 1292442 -2111198 -356919 -5161742 1053473 2969712 -273633 -2531394 -1476904 4196610 -668689 5223226 2363388 -4749074 1453637 5172566 3098573 -6607553 3035344 9239499 3245836 8515152 5939773 -8006669 -1571201 2987555 2285896 -328166 8447115 8300141 4968943 -3553...

output:

0
0
34972
0
0
0
0
43716
0
5094
80848
0
0
11803
0
153
8247
349
22863
34888
4
46178
0
22091
19029
28735
63305
463
60599
44410
0
42798
0
21737
0
12846
5408
17461
41948
0
0
19273
0
94563
88252
0
75457
6882
1086
0
29281
0
14787
0
0
8704
1723
4723
41889
2473
71164
36950
0
0
58201
9
0
0
2111
7905
0
0
0
165...

result:

ok 59807 lines

Test #15:

score: 0
Accepted
time: 3660ms
memory: 61968kb

input:

200000 200000
8567007 -5226429 -2953979 247299 -1678504 -2081438 5564386 64495 5819388 -1707511 -2301065 4403497 -490222 6996074 -1035827 -3096248 -974733 -5496322 -1026076 164464 270319 6319804 3943329 1332077 5608709 -341708 2195141 3854122 4589360 -2638935 1302497 -6407416 -4772682 2652488 232211...

output:

0
6630
84215
0
0
12454
36522
0
20400
0
7425
0
12086
87353
25152
0
0
0
12970
12706
0
29863
25443
30543
33100
31334
9066
0
29065
0
8403
22000
58738
0
0
59561
0
0
7618
33455
15278
28182
81915
0
0
0
68627
0
0
38959
57160
49732
1554
37656
17318
0
39
26764
61115
22691
2148
72630
10895
4228
57426
40447
0
3...

result:

ok 59769 lines

Test #16:

score: 0
Accepted
time: 3495ms
memory: 83904kb

input:

200000 200000
-2424506 -2412587 375978 3903889 8078697 -6184291 3477404 2131469 -871 -4730294 531835 300684 -3322834 -121479 -4409421 -4332635 970753 8953808 3686560 1844489 -5025765 -508325 -1918502 -8746620 1027975 2735651 -5729629 2631941 4613862 826030 -1023189 -5287521 -2848446 1034127 2203986 ...

output:

26150
22136
0
30634
49445
2535
0
14848
0
0
166478
206018
7674
176
0
0
89413
0
73833
7206
34575
179574
52642
27887
0
134120
57825
16750
74616
121417
0
127063
55
7131
103582
0
0
26663
55389
128697
112435
21161
0
0
0
0
45280
0
0
54712
7600
112206
0
212602
16032
19005
105271
78179
0
0
16955
53039
0
2343...

result:

ok 40220 lines

Test #17:

score: 0
Accepted
time: 3548ms
memory: 84860kb

input:

200000 200000
4157337 2051459 -2226442 -2859846 -1363238 3318798 -6086454 -2961180 5480585 -253878 -2198660 4422336 -1138307 6264707 -2662099 875139 -1532831 1526998 -1544412 1211341 1422737 859329 -995081 -759657 3803914 -200321 3640303 -858696 -9068385 -5597302 -1548498 -3046862 1840864 -7479957 2...

output:

13536
34482
0
0
55019
0
28302
84777
11433
186337
46112
17244
0
0
830
92517
0
122200
81940
137451
136677
148790
39062
0
44000
16973
49526
23770
78841
4408
0
0
11613
28718
0
0
30008
117773
174013
190054
0
38136
15010
68640
51254
2774
39397
74526
1874
0
136654
49924
0
46905
63671
16702
0
37421
4
0
4371...

result:

ok 39885 lines

Test #18:

score: 0
Accepted
time: 3525ms
memory: 84372kb

input:

200000 200000
-1944203 -4277932 1215473 -2549998 2964206 -1521691 -2377568 1677403 7157590 -156464 -6322029 1830838 3582053 7214339 -3080059 4031082 4258944 -858202 -737466 -203208 5352226 -6561338 1463355 6305121 4459725 46467 -4922472 3938727 -836994 -5595204 1293604 -722127 1049183 -386905 629972...

output:

128001
40881
0
94530
145226
193
0
0
26998
105006
115264
0
0
0
139243
142702
30991
0
0
56465
140392
81420
36795
0
71596
23044
32242
1030
0
0
26501
26555
28500
1488
230011
110993
308
0
173487
0
101032
1694
56453
67813
570
75772
101224
67002
23966
0
0
0
0
0
0
91992
0
0
0
0
100811
1275
0
50159
14120
315...

result:

ok 39992 lines

Test #19:

score: 0
Accepted
time: 4130ms
memory: 84812kb

input:

200000 200000
2020187 5752964 3729782 -3773575 -1227773 -4166269 -3406569 1132930 -2643694 -6039887 4782561 -1547560 -6441999 -4282759 262021 8264684 -2551868 6809020 -2692592 -2559467 8651479 527358 -5490633 2233287 1676764 3633016 895545 -1173517 -5880163 -2616915 -8857064 9434031 -4751149 998615 ...

output:

0
83556
56770
43620
5745
19259
0
0
0
22474
21122
148418
0
51167
51202
32151
0
5077
186593
17447
2193
6450
268
0
4102
20010
79701
70126
212837
0
0
28199
105781
0
93371
0
29459
0
0
42775
0
150313
0
35811
1590
44789
181583
56
0
0
110541
0
170694
223961
93470
23496
7603
152268
21799
83254
67
0
0
66107
1...

result:

ok 39809 lines

Test #20:

score: 0
Accepted
time: 4120ms
memory: 84564kb

input:

200000 200000
-5803732 -1015248 5033042 -4027966 -6335081 777716 5484060 6956103 5376739 -756548 -2111304 -297680 -3180617 -5018521 -803454 -1352740 372489 -2385092 -5557764 -1193567 -689952 -5080322 5863291 -1041878 -2543762 -2185503 1042196 1605817 5967643 5303210 -5871199 4217287 1513349 -1178448...

output:

44526
2979
0
144133
95614
101402
0
105709
362
21073
84972
0
128753
7979
0
2269
140679
9943
40477
133023
199178
316
10787
50107
64969
58248
677
0
0
20645
0
97788
0
14839
0
61195
81509
156373
14932
3054
4860
72727
0
63729
1786
11218
18503
3469
63859
61639
174282
100706
7627
0
10872
0
3241
0
91613
1052...

result:

ok 40037 lines

Test #21:

score: 0
Accepted
time: 4113ms
memory: 84380kb

input:

200000 200000
-262667 -1639231 -4099912 303606 -6035762 -242834 3420080 7049036 3392046 4240671 -1824766 4760436 3308771 1649215 -2530067 -2338543 1046789 2544361 -846843 -162281 623849 3870102 1624163 -5315221 5342309 -2981470 -5836301 6333766 -7968029 -3462116 689395 -133932 -5645666 -2945538 -451...

output:

32122
147410
0
114475
114
32502
0
26136
0
0
1809
0
108280
0
32277
48900
65834
21923
0
68189
1085
24004
3335
19242
0
9676
121214
4101
61849
3353
149163
43384
53395
5
129244
0
0
0
46732
4546
0
2890
104530
0
13737
0
0
0
68848
84053
98596
149937
133478
2562
13762
78310
4534
148161
36447
0
84955
0
16164
...

result:

ok 39899 lines

Test #22:

score: 0
Accepted
time: 5184ms
memory: 65544kb

input:

200000 200000
1355855 -8231041 3957486 5457365 4940777 1471127 2629869 -2568612 3891882 2593904 -3670773 1274445 5817023 -7266326 -649453 563335 -2504295 4259024 986470 -3906577 4133241 3251208 2578032 5849055 5955528 3009124 437248 -9471234 -1846927 1332558 3010219 7997851 -1949622 2258304 260683 -...

output:

44097
0
0
789
3647
24533
0
9625
1606
766
0
0
98621
10032
80790
0
39117
25510
51453
20041
112174
4529
16319
4339
0
0
28496
0
16863
249
0
0
251
0
0
0
0
4682
0
19595
7420
0
0
0
42475
0
19366
46319
12766
0
100680
37403
596
5
709
10418
2339
73279
68326
32135
0
27174
60205
0
0
3
0
0
45100
0
0
0
0
0
2
0
59...

result:

ok 40293 lines

Test #23:

score: 0
Accepted
time: 5185ms
memory: 65948kb

input:

200000 200000
-3936789 1087317 4548999 2242319 -1097843 -1998470 5324823 2063090 7739127 -468853 3999140 -1848429 -5206505 771794 2617946 -4486900 -4921270 5068514 -3533264 392208 1721349 6222243 -2662603 -5211753 3630308 -2522169 -60193 -920829 -1755632 3581831 6738862 -2519285 7703599 3163543 -429...

output:

68625
100735
0
55961
49028
0
2823
1767
56161
107488
20100
73081
100339
55
2079
0
0
79693
41200
0
0
15565
112488
22022
17802
53450
64169
0
43326
23246
44659
833
0
50392
0
0
0
0
4
9510
0
59222
2318
0
0
12648
6716
1219
35473
59680
5288
12273
89162
76277
84906
0
0
46578
77953
13596
355
0
3956
13915
9121...

result:

ok 39923 lines

Test #24:

score: 0
Accepted
time: 5368ms
memory: 63972kb

input:

200000 200000
7198514 8215112 -3254257 4578258 2607656 321286 -4272606 8843976 1428728 -737777 -2511695 2177596 -1328518 -9342597 5155151 -1298997 838473 196525 8020204 2196007 -1272405 3492960 -4230361 -1735748 1735249 -2696303 -4726074 1106889 9293062 1786471 1187183 -4095131 -6007334 1273157 2548...

output:

13501
5477
13102
57954
0
41448
0
0
76228
65401
1358
316
3731
90082
31091
8824
0
0
0
15683
12434
81177
32346
54910
2797
0
27530
0
357
0
7327
0
8554
1171
2951
0
7032
4
63248
40013
0
38864
28565
0
0
34135
46418
1516
12927
970
28009
0
0
29
77622
2899
23137
0
39422
19668
3924
29129
612
17529
49097
235
0
...

result:

ok 40242 lines

Test #25:

score: 0
Accepted
time: 5187ms
memory: 67480kb

input:

200000 200000
2071792 1447027 -6012685 68640 6735591 3074281 5740946 183332 2632779 281995 324077 -1720988 -5780906 5626056 2270209 -6615491 -6366387 -4728141 -107605 1231185 279160 -268171 7552889 -4609082 4989546 -1908032 -4329931 -8022989 2545110 -2156885 -2842032 5059931 -3043842 -9809688 -62637...

output:

0
23910
49755
113479
0
21054
0
0
7131
0
2863
68536
112300
11294
0
0
36887
3911
27942
0
25908
80694
17254
83739
110258
65826
12572
22959
233
6399
16826
27186
373
0
0
2326
100197
0
95457
0
53000
372
5
36927
36982
0
0
37215
85491
35806
109
0
0
14256
0
19404
0
62940
57010
0
59623
6265
0
0
0
26643
4532
1...

result:

ok 40241 lines

Test #26:

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

input:

5 6
1 3 3 2 2
1 2
1 3
2 4
2 5
4 3 4 2
3 2 6 2
4 0 7 1
1 5 6 1
2 2 7
4 0 3 0

output:

3
4
2

result:

ok 3 lines

Test #27:

score: 0
Accepted
time: 86ms
memory: 36412kb

input:

5000 5000
-2935715 884931 6623154 -3760160 -6639540 2047907 6858058 637875 2506650 1846954 5717570 6824922 3391920 29386 -99734 -5963622 3719405 -1058473 4435872 -1284857 213114 4458576 6294626 -1533781 -854484 -3985355 107359 510443 534290 3440546 -3069835 -1104121 -2922479 -3359544 3589173 -329433...

output:

2262
0
85
1427
971
2
14
372
2016
833
820
2380
0
253
778
0
576
576
2011
0
48
0
7
1241
143
930
41
0
0
1345
1606
0
0
1050
109
163
1910
2389
492
1006
869
423
0
0
0
2555
1
135
0
0
2492
0
915
687
1766
360
0
0
0
2479
0
863
9
1479
0
0
915
67
2588
876
1912
0
31
213
394
0
226
2047
454
285
2615
2615
1151
0
1
2...

result:

ok 1004 lines

Test #28:

score: 0
Accepted
time: 3532ms
memory: 84764kb

input:

200000 200000
4559006 -3085416 4899001 1617575 2702334 -6731969 -6028066 4282498 -181213 8300754 -85498 8247175 -2398665 -4497165 7982062 3992010 3826438 -7284029 -4388766 6536852 -3591752 -291379 5767445 -556405 1613544 -2967891 -5491681 -367487 16405 1682314 -2930289 -3570593 1437278 783343 189419...

output:

0
0
0
226366
0
20419
52261
1047
89907
0
179344
99603
37318
7072
5655
125664
41478
152963
205
91710
202613
85451
46346
168882
23409
0
1562
0
126105
24921
56013
28289
0
0
40571
64515
36567
10746
191614
49123
14427
30471
0
187610
0
0
0
0
0
86595
0
0
160467
1566
237687
0
0
22915
0
431
0
81661
0
4838
0
8...

result:

ok 40059 lines

Test #29:

score: 0
Accepted
time: 5395ms
memory: 63100kb

input:

200000 200000
-5520162 2603667 -1124036 483096 9318257 266293 2564786 -695499 1679948 8463164 -862725 4596058 1485123 3144238 -4248320 2198661 536350 -3814045 2297839 -178136 -612466 -6001852 -3337045 6298206 -4540219 -7038282 780943 -220737 2794480 60691 1917217 3584156 -1730994 -2762915 -7032483 -...

output:

25909
53797
0
64253
48160
0
53851
0
824
0
2401
11401
54407
0
0
0
8392
97221
82604
13
59028
0
73415
0
0
0
4322
2947
0
0
0
0
4696
6636
38263
39263
45901
43089
5320
8
199
23715
62377
67493
38403
0
5841
3485
11775
2675
25262
40549
20
8084
274
56593
0
49309
5
2149
61312
85640
0
0
30332
17933
1906
29145
0...

result:

ok 39779 lines