QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670152#4223. 盒Starrykiller100 ✓651ms65828kbC++238.3kb2024-10-23 20:39:572024-10-23 20:39:57

Judging History

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

  • [2024-10-23 20:39:57]
  • 评测
  • 测评结果:100
  • 用时:651ms
  • 内存:65828kb
  • [2024-10-23 20:39:57]
  • 提交

answer

// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever! 
#include <bits/stdc++.h>

using namespace std;

template<typename L, typename R>
auto range(L l, R r) { return views::iota(l,r); }
auto rev=views::reverse;

template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmax(T &a, T b) { a=max(a,b); }
template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmin(T &a, T b) { a=min(a,b); }

namespace sk {
    // modint: https://www.cnblogs.com/hzy1/p/16344746.html
    // Edited by Starrykiller.
    using i64=int64_t;
    using i128=__int128;
    using u128=unsigned __int128;
    using u64=uint64_t;
    using i32=int32_t;
    using u32=uint32_t;
    struct barrett { // From Atcoder Library.
        u32 _m;
        u64 im;
        explicit barrett(u32 m) : _m(m), im((u64)(-1)/m+1) {}
        u32 umod() const { return _m; }
        u32 mul(u32 a, u32 b) const {
            u64 z=a; z*=b;
            u64 x=(u64)((u128(z)*im) >> 64);
            u64 y = x * _m;
            return (u32)(z-y+(z<y?_m:0));
        }
    };
    constexpr i32 inverse(i32 a, i32 m) { i32 r=1;
        while (a>1) { i32 t=m/a; r=i64(r)*(m-t)%m; a=m-t*a; }
        return r;
    }
    template<i32 p>
    struct static_modint { 
        using mi=static_modint;
        public:
        constexpr static_modint(i64 x) : x(normal(x%p)) {}
        constexpr static_modint(i32 x, std::nullptr_t) : x(x) {}
        constexpr static_modint(): x(0) {}
        constexpr i32 normal(i32 x) { 
            if (x>=p) x-=p;
            return x+((x>>31)&p); 
        }
        constexpr i32 val() const { return x; }
        constexpr static i32 mod() { return p; }
        constexpr explicit operator bool() const { return x; }
        constexpr mi inv() const { assert(x!=0); return mi(inverse(x,p),nullptr); }
        constexpr mi pow(i64 x) const { assert(x>=0); mi a=*this, res=1;
            while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
        constexpr mi operator-() const { return mi(p-x); }
        constexpr mi& operator+=(const mi &rhs) { x=normal(x+rhs.x); return *this; }
        constexpr mi& operator-=(const mi &rhs) { x=normal(x-rhs.x); return *this; }
        constexpr mi& operator++() { return (*this)+=1; }
        constexpr mi& operator--() { return (*this)-=1; }
        constexpr mi& operator*=(const mi &rhs) { x=i64(x)*rhs.x%p; return *this; }
        constexpr mi& operator/=(const mi &rhs) { return *this *= rhs.inv(); }
        constexpr friend mi operator+(const mi &lhs, const mi &rhs) { auto res=lhs; res+=rhs; return res; }
        constexpr friend mi operator-(const mi &lhs, const mi &rhs) { auto res=lhs; res-=rhs; return res; }
        constexpr friend mi operator*(const mi &lhs, const mi &rhs) { auto res=lhs; res*=rhs; return res; }
        constexpr friend mi operator/(const mi &lhs, const mi &rhs) { auto res=lhs; res/=rhs; return res; }
        constexpr friend mi operator++(mi &x, i32) { auto tmp=x; x+=1; return tmp; }
        constexpr friend mi operator--(mi &x, i32) { auto tmp=x; x-=1; return tmp; }
        constexpr friend std::istream& operator>>(std::istream &is, mi &a) { i64 v; is>>v; a=v; return is; }
        constexpr friend std::ostream& operator<<(std::ostream &os, const mi &a) { os<<a.val(); return os; }
        constexpr bool operator==(const mi& rhs) const { return val()==rhs.val(); }
        constexpr bool operator!=(const mi& rhs) const { return val()!=rhs.val(); }
        private:
        i32 x;
    };
    template<i32 id>
    struct dynamic_modint { 
        using mi=dynamic_modint;
        public:
        constexpr dynamic_modint(i64 x) : x(normal(x%mod())) {}
        constexpr dynamic_modint(i32 x, std::nullptr_t) : x(x) {}
        constexpr dynamic_modint(): x(0) {}
        constexpr i32 normal(i32 x) { 
            auto p=mod();
            if (x>=p) x-=p;
            return x+((x>>31)&p); 
        }
        constexpr i32 val() const { return x; }
        constexpr static void set_mod(i32 m) { assert(m>=1); bt=barrett((u32)m); }
        constexpr static i32 mod() { return bt.umod(); }
        constexpr explicit operator bool() const { return x; }
        constexpr mi inv() const { assert(x!=0); return mi(inverse(x,mod()),nullptr); }
        constexpr mi pow(i64 x) const { assert(x>=0); mi a=*this, res=1;
            while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
        constexpr mi operator-() const { return mi(mod()-x); }
        constexpr mi& operator+=(const mi &rhs) { x=normal(x+rhs.x); return *this; }
        constexpr mi& operator-=(const mi &rhs) { x=normal(x-rhs.x); return *this; }
        constexpr mi& operator++() { return (*this)+=1; }
        constexpr mi& operator--() { return (*this)-=1; }
        constexpr mi& operator*=(const mi &rhs) { x=bt.mul(val(),rhs.val()); return *this; }
        constexpr mi& operator/=(const mi &rhs) { return *this *= rhs.inv(); }
        constexpr friend mi operator+(const mi &lhs, const mi &rhs) { auto res=lhs; res+=rhs; return res; }
        constexpr friend mi operator-(const mi &lhs, const mi &rhs) { auto res=lhs; res-=rhs; return res; }
        constexpr friend mi operator*(const mi &lhs, const mi &rhs) { auto res=lhs; res*=rhs; return res; }
        constexpr friend mi operator/(const mi &lhs, const mi &rhs) { auto res=lhs; res/=rhs; return res; }
        constexpr friend mi operator++(mi &x, i32) { auto tmp=x; x+=1; return tmp; }
        constexpr friend mi operator--(mi &x, i32) { auto tmp=x; x-=1; return tmp; }
        constexpr friend std::istream& operator>>(std::istream &is, mi &a) { i64 v; is>>v; a=v; return is; }
        constexpr friend std::ostream& operator<<(std::ostream &os, const mi &a) { os<<a.val(); return os; }
        constexpr bool operator==(const mi& rhs) const { return val()==rhs.val(); }
        constexpr bool operator!=(const mi& rhs) const { return val()!=rhs.val(); }
        private:
        i32 x; 
        static barrett bt;
    };
    template<i32 id> barrett dynamic_modint<id>::bt(998244353);
    using modint998244353=static_modint<998244353>;
    using modint1000000007=static_modint<1000000007>;
    using mint=dynamic_modint<-1>; 
};
using ll=sk::modint998244353;
using i64=int64_t; constexpr int p=998'244'353;

template<int N>
constexpr auto get_fac() {
    vector<ll> fac(N+1), ifac(N+1);
    fac[0]=ifac[0]=1;
    for (int i=1; i<=N; ++i)
        fac[i]=fac[i-1]*i;
    ifac[N]=fac[N].inv();
    for (int i=N-1; i; --i)
        ifac[i]=ifac[i+1]*(i+1);
    return make_pair(fac,ifac);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
int T; cin>>T;
// int T=1;
    constexpr int N=4e6;
    auto [fac,ifac]=get_fac<N>();
    auto C=[&](int n, int m)->ll {
        if (!m) return 1;
        if (n<m || n<0 || m<0) return 0; 
        return fac[n]*ifac[n-m]*ifac[m];
    };

    auto f=[&](int n, int m, int i, int k) {
        ll ans=0;
        for (int j=0; j<=k; ++j)
            ans+=C(n+m-i-j,n-i)*C(j+i-1,i-1);
        return ans;
    };

while (T--) [&]{
    int n; 
    cin>>n;
    vector<int> a(n);
    for (int sum=0; auto &i: a) cin>>i, i=(sum+=i);
    int m=a.back(); 
    vector<int> val(n-1); for (auto &i: val) cin>>i;
    --n;
    a.insert(begin(a),0); val.insert(begin(val),0);
    ll ans=0;
    vector<ll> F(n+1);
    ll cur=f(n,m,1,a[1]); int k=a[1];
    for (auto i: range(1,n+1)) {
        F[i]+=2*a[i]*cur;
        if (i==n) break;
        while (k<a[i+1]) {
            ++k;
            cur+=C(n+m-i-k,n-i)*C(k+i-1,i-1);
        }
        cur-=C((i+1)+k-1,(i+1)-1)*C(n-(i+1)+m-k,n-(i+1)+1);
    }

    cur=f(n,m,1,m); k=m;
    for (auto i: range(1,n+1)) {
        F[i]-=a[i]*cur;
        if (i==n) break;
        cur-=C((i+1)+k-1,(i+1)-1)*C(n-(i+1)+m-k,n-(i+1)+1);
    }

    cur=f(n+1,m-1,2,a[1]-1); k=a[1]-1;
    for (auto i: range(1,n+1)) {
        F[i]-=2*i*cur;
        if (i==n) break;
        while (k<a[i+1]-1) {
            ++k;
            cur+=C(n+m-i-k-1,n-i)*C(i+k,i);
        }        
        
        cur-=C((i+1)+k,(i+1))*C(n-(i+1)+m-1-k,n-(i+1)+1);
    }

    cur=f(n+1,m-1,2,m-1); k=m-1;
    for (auto i: range(1,n+1)) {
        F[i]+=i*cur;
        if (i==n) break;        
        cur-=C((i+1)+k,(i+1))*C(n-(i+1)+m-1-k,n-(i+1)+1);
    }

    for (auto i: range(1,n+1))
        ans+=val[i]*F[i];
    
    cout<<ans<<'\n';
}();
}

詳細信息


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 36ms
memory: 65648kb

input:

1000
5
1 2 0 0 2
1 1 1 1
5
0 1 0 4 0
1 1 1 1
5
2 3 0 0 0
1 1 1 1
5
1 1 0 3 0
1 1 1 1
5
1 0 2 2 0
1 1 1 1
5
0 3 0 1 1
1 1 1 1
5
2 0 0 3 0
1 1 1 1
5
0 4 0 1 0
1 1 1 1
5
1 2 2 0 0
1 1 1 1
5
1 2 1 0 1
1 1 1 1
5
0 1 1 0 3
1 1 1 1
5
0 0 3 1 1
1 1 1 1
5
4 0 0 1 0
1 1 1 1
5
2 0 1 0 2
1 1 1 1
5
0 1 2 2 0
1 1...

output:

604
684
924
562
550
562
618
684
670
572
738
634
938
624
564
642
1022
684
726
624
586
600
672
526
574
754
822
712
1020
582
658
568
768
592
868
822
754
592
576
564
642
808
564
726
1022
560
560
618
562
606
634
592
938
628
1020
606
690
670
526
618
628
868
670
600
810
684
588
550
648
684
550
562
536
822
...

result:

ok 1000 lines

Test #2:

score: 5
Accepted
time: 48ms
memory: 65684kb

input:

1000
5
0 0 3 2 0
1 1 1 1
5
0 2 1 0 2
1 1 1 1
5
1 1 0 3 0
1 1 1 1
5
3 1 0 0 1
1 1 1 1
5
1 0 0 1 3
1 1 1 1
5
0 1 3 0 1
1 1 1 1
5
0 5 0 0 0
1 1 1 1
5
1 1 0 3 0
1 1 1 1
5
4 0 1 0 0
1 1 1 1
5
0 1 2 0 2
1 1 1 1
5
1 2 0 1 1
1 1 1 1
5
0 2 1 2 0
1 1 1 1
5
1 1 1 1 1
1 1 1 1
5
3 0 0 0 2
1 1 1 1
5
2 1 0 1 1
1 1...

output:

648
582
562
808
808
574
882
562
1022
606
548
540
512
756
604
672
684
808
810
1260
726
672
568
1260
536
658
684
586
648
582
536
924
586
560
656
726
582
604
754
576
670
592
586
618
564
562
726
628
568
868
600
536
670
714
924
808
548
726
670
574
550
712
550
582
714
562
582
1260
588
882
712
690
1136
684...

result:

ok 1000 lines

Test #3:

score: 5
Accepted
time: 36ms
memory: 65764kb

input:

5
9
2 1 2 1 1 1 0 0 1
64441563 797608723 942502970 533863371 513086090 746473949 428148282 824687114
9
2 1 0 0 1 1 2 1 1
357194979 60738266 185201880 659655681 91157881 186097011 305593400 735854260
9
5 1 0 1 0 1 0 0 1
100945837 161415380 584897137 338229880 478210934 517640875 276897589 404899480
9...

output:

166289283
895455295
733275678
590188223
653043103

result:

ok 5 lines

Test #4:

score: 5
Accepted
time: 38ms
memory: 65688kb

input:

5
9
2 1 0 3 0 1 2 0 0
14399309 615700834 990195320 232910103 497942608 662410204 85583523 29348873
9
0 4 0 0 0 2 3 0 0
666973109 216575957 709836635 363606637 454780119 714712114 868661423 39323875
9
3 3 0 0 0 0 1 1 1
661125856 61965314 875115448 444871086 310288485 430098658 795362211 948050121
9
2...

output:

663021142
691106730
461190819
111225759
954800036

result:

ok 5 lines

Test #5:

score: 5
Accepted
time: 44ms
memory: 65636kb

input:

10
2000
0 0 3 0 3 0 0 0 4 0 4 0 0 0 7 3 3 0 0 0 0 1 1 0 2 3 1 3 3 2 1 0 0 0 0 1 0 1 1 0 1 0 4 2 0 0 0 0 0 0 0 1 1 4 1 2 0 0 3 1 5 0 0 0 1 7 2 3 2 0 1 0 5 0 5 0 0 0 4 2 2 0 0 0 2 0 3 1 1 0 0 4 1 2 1 4 2 0 0 1 1 5 0 4 0 1 0 2 1 0 2 0 0 0 1 1 1 0 0 0 0 4 1 2 0 0 0 1 0 4 2 0 2 1 0 0 1 0 0 0 0 0 2 1 1 3 ...

output:

677203754
806267485
380218391
160903957
636403648
885411081
488211568
884855269
572061500
854586776

result:

ok 10 lines

Test #6:

score: 5
Accepted
time: 44ms
memory: 65752kb

input:

10
2000
0 1 0 2 0 0 1 0 0 3 1 4 1 1 0 0 2 0 0 0 1 1 6 1 0 0 0 0 0 1 0 0 0 0 0 2 0 0 3 0 0 0 0 0 5 1 0 0 2 1 0 1 2 0 5 0 0 0 0 5 4 4 0 2 3 0 0 3 2 3 0 0 1 2 0 1 9 0 1 0 0 0 3 1 6 1 1 0 2 0 0 0 1 1 4 0 3 3 0 2 1 0 1 0 1 0 0 1 1 0 0 6 0 0 4 0 1 0 4 0 0 0 0 1 0 0 2 4 0 1 0 1 1 7 0 1 0 0 0 3 0 0 2 2 1 1 ...

output:

13138131
568953787
794561691
844899130
15143729
565995880
443870964
625990050
170101909
962072317

result:

ok 10 lines

Test #7:

score: 5
Accepted
time: 45ms
memory: 65648kb

input:

10
2000
0 1 0 0 2 2 0 1 1 0 1 0 0 1 2 1 0 0 1 0 0 1 0 2 0 0 0 0 0 1 0 0 0 1 1 1 2 1 0 0 2 0 2 0 0 7 0 0 0 1 3 1 0 1 2 1 0 1 0 2 1 2 2 0 0 0 0 0 0 2 0 1 2 1 0 1 1 0 2 0 3 0 0 1 1 1 0 2 0 0 0 0 1 0 0 0 0 0 0 2 0 1 0 7 0 4 2 0 0 1 0 0 1 0 0 5 0 0 2 3 2 0 1 2 0 1 0 5 0 0 3 3 2 0 1 1 4 0 2 1 0 1 1 1 0 0 ...

output:

927739833
478537355
781908267
477242825
762969873
218922702
324588900
362688816
269194120
851086706

result:

ok 10 lines

Test #8:

score: 5
Accepted
time: 41ms
memory: 65600kb

input:

10
2000
0 0 1 0 3 0 0 0 0 2 2 2 1 0 0 2 0 0 0 1 2 1 0 1 0 0 1 1 0 0 2 0 3 1 2 0 1 0 2 1 0 0 0 0 0 2 1 0 1 0 2 1 0 1 2 0 0 0 0 3 1 3 0 0 0 1 2 0 2 0 3 1 0 1 1 0 1 0 1 0 0 0 3 0 0 2 2 1 1 2 6 0 0 0 0 0 1 1 1 0 0 1 2 0 1 1 4 1 0 0 0 0 2 0 1 1 1 1 2 2 1 3 2 0 1 1 0 0 0 0 2 2 0 0 0 0 0 1 2 0 1 1 1 0 2 0 ...

output:

195292244
782066652
834893430
951491168
373431347
905607285
640769720
147693846
769903465
856040696

result:

ok 10 lines

Test #9:

score: 5
Accepted
time: 87ms
memory: 65828kb

input:

10
2000
5 18 179 19 200 71 72 241 70 268 2 32 43 179 39 436 69 57 77 196 212 93 57 128 66 29 248 16 279 102 286 38 12 122 3 84 51 91 39 4 59 31 129 278 3 258 67 171 18 92 80 97 35 48 87 167 22 0 152 110 195 174 59 102 354 136 11 82 87 56 21 78 172 376 79 284 21 51 66 46 97 251 12 92 13 53 31 25 60 9...

output:

524012922
866598816
237070259
614697317
449978353
27094015
208395168
317414506
932279540
378501563

result:

ok 10 lines

Test #10:

score: 5
Accepted
time: 89ms
memory: 65648kb

input:

10
2000
85 186 177 278 2 12 67 247 6 197 142 32 47 61 13 33 184 9 198 71 82 157 61 129 204 35 67 91 261 104 47 47 149 126 15 45 74 278 250 56 217 13 38 120 67 2 20 74 0 8 75 43 120 83 52 112 41 98 22 5 74 184 33 194 109 73 109 59 103 6 39 146 118 26 1 9 0 93 8 246 56 83 2 43 101 68 36 103 384 130 17...

output:

178693471
895462832
950343202
873193760
587878271
88200837
582769494
865539655
647847472
355351193

result:

ok 10 lines

Test #11:

score: 5
Accepted
time: 94ms
memory: 65692kb

input:

10
2000
28 10 97 27 85 51 88 20 290 96 147 63 31 171 29 55 325 87 73 70 60 23 1 69 370 389 63 74 206 60 28 74 312 346 26 45 389 137 76 137 377 386 5 246 54 344 11 50 55 418 30 76 205 66 41 112 198 106 29 44 176 6 21 1 20 72 74 2 40 135 47 286 104 63 19 112 4 98 6 56 113 189 57 177 1 70 177 26 153 26...

output:

29504387
543409712
462494552
889682671
915374306
572599220
112489766
744902721
628078452
524299454

result:

ok 10 lines

Test #12:

score: 5
Accepted
time: 97ms
memory: 65660kb

input:

10
2000
53 99 243 121 0 61 132 124 135 6 191 8 149 19 114 56 93 55 65 35 75 68 2 397 39 117 66 177 203 134 91 67 44 12 94 23 283 176 103 62 273 307 16 126 173 208 54 69 2 15 33 52 82 84 188 178 73 187 39 22 76 27 29 123 18 33 96 66 78 192 9 47 115 60 44 65 203 25 100 54 309 68 71 42 380 121 6 79 295...

output:

137929288
585638786
919393844
664607978
576268329
182764363
622337534
522169037
945923808
516644682

result:

ok 10 lines

Test #13:

score: 5
Accepted
time: 99ms
memory: 65712kb

input:

2
200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

634736921
694614969

result:

ok 2 lines

Test #14:

score: 5
Accepted
time: 105ms
memory: 65752kb

input:

2
200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

648271884
299244125

result:

ok 2 lines

Test #15:

score: 5
Accepted
time: 79ms
memory: 65608kb

input:

2
200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

497119900
756171733

result:

ok 2 lines

Test #16:

score: 5
Accepted
time: 85ms
memory: 65828kb

input:

2
200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

543840180
335626556

result:

ok 2 lines

Test #17:

score: 5
Accepted
time: 105ms
memory: 65616kb

input:

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

output:

668642168
28182409

result:

ok 2 lines

Test #18:

score: 5
Accepted
time: 100ms
memory: 65760kb

input:

2
200000
0 2 1 0 0 0 2 0 0 2 2 1 7 3 0 0 3 0 0 4 1 1 0 5 1 1 2 0 0 2 0 2 0 2 0 1 1 2 0 0 1 0 2 3 2 0 0 0 0 2 0 2 0 1 2 0 1 0 4 0 0 2 0 1 0 1 0 0 0 5 0 1 0 0 1 2 1 2 0 2 1 0 0 1 0 0 0 2 0 1 0 1 0 1 0 3 0 2 1 1 1 1 1 1 0 1 0 0 7 2 3 0 0 1 1 1 2 0 0 1 2 0 0 0 2 2 0 0 3 0 0 1 2 0 0 5 1 0 0 0 0 0 3 2 0 0...

output:

241356767
868078483

result:

ok 2 lines

Test #19:

score: 5
Accepted
time: 651ms
memory: 65692kb

input:

5
500000
11 7 4 2 1 24 2 6 2 5 0 1 1 0 7 1 0 16 3 1 0 2 2 0 9 3 1 5 0 0 0 7 1 13 11 4 0 0 2 5 2 2 3 1 1 11 3 0 0 4 1 4 3 1 0 12 2 4 2 3 6 6 1 3 10 1 1 1 10 1 2 1 0 13 6 18 1 1 7 3 2 12 3 1 1 2 6 12 0 1 9 14 7 3 0 0 1 2 1 3 2 8 2 2 5 2 7 0 4 6 7 11 2 7 1 1 0 1 1 9 6 6 5 1 3 8 0 2 0 0 6 3 0 0 2 0 1 5 ...

output:

98889056
484756281
930912610
263147365
849729187

result:

ok 5 lines

Test #20:

score: 5
Accepted
time: 644ms
memory: 65604kb

input:

5
500000
13 6 2 0 3 4 3 1 2 2 14 5 0 5 1 3 2 6 0 5 8 0 15 2 0 2 0 11 2 0 1 0 7 0 11 2 6 3 8 0 3 0 1 2 0 1 3 7 0 9 0 0 2 4 5 0 6 20 4 1 1 3 3 1 2 2 1 0 1 12 9 5 3 0 0 1 4 18 0 8 10 8 7 1 4 23 1 4 1 6 0 6 2 1 4 1 2 0 0 4 19 9 4 4 0 3 1 14 2 6 1 14 0 7 0 1 0 1 2 0 17 0 8 19 1 0 2 3 1 0 6 3 0 2 5 3 0 1 ...

output:

83959233
329673420
320596871
9954616
119639166

result:

ok 5 lines

Extra Test:

score: 0
Extra Test Passed