QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625827#8410. Splatanie ciągów [A]chenxinyang20064 2042ms74504kbC++205.1kb2024-10-09 21:17:492024-10-09 21:17:51

Judging History

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

  • [2024-10-09 21:17:51]
  • 评测
  • 测评结果:4
  • 用时:2042ms
  • 内存:74504kb
  • [2024-10-09 21:17:49]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
    if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
    if(x > y) x = y;
}

inline int popcnt(int x){
    return __builtin_popcount(x);
}

inline int ctz(int x){
    return __builtin_ctz(x);
}

template <int P>
class mod_int
{
    using Z = mod_int;

private:
    static int mo(int x) { return x < 0 ? x + P : x; }

public:
    int x;
    int val() const { return x; }
    mod_int() : x(0) {}
    template <class T>
    mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
    bool operator==(const Z &rhs) const { return x == rhs.x; }
    bool operator!=(const Z &rhs) const { return x != rhs.x; }
    Z operator-() const { return Z(x ? P - x : 0); }
    Z pow(long long k) const
    {
        Z res = 1, t = *this;
        while (k)
        {
            if (k & 1)
                res *= t;
            if (k >>= 1)
                t *= t;
        }
        return res;
    }
    Z &operator++()
    {
        x < P - 1 ? ++x : x = 0;
        return *this;
    }
    Z &operator--()
    {
        x ? --x : x = P - 1;
        return *this;
    }
    Z operator++(int)
    {
        Z ret = x;
        x < P - 1 ? ++x : x = 0;
        return ret;
    }
    Z operator--(int)
    {
        Z ret = x;
        x ? --x : x = P - 1;
        return ret;
    }
    Z inv() const { return pow(P - 2); }
    Z &operator+=(const Z &rhs)
    {
        (x += rhs.x) >= P && (x -= P);
        return *this;
    }
    Z &operator-=(const Z &rhs)
    {
        (x -= rhs.x) < 0 && (x += P);
        return *this;
    }
    Z operator-()
    {
        return -x;
    }
    Z &operator*=(const Z &rhs)
    {
        x = 1ULL * x * rhs.x % P;
        return *this;
    }
    Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o)                                  \
    friend T operator o(const Z &lhs, const Z &rhs) \
    {                                               \
        Z res = lhs;                                \
        return res o## = rhs;                       \
    }
    setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
    
    friend istream& operator>>(istream& is, mod_int& x)
    {
        long long tmp;
        is >> tmp;
        x = tmp;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mod_int& x)
    {
        os << x.val();
        return os;
    }
};

using Z = mod_int<mod>;
Z power(Z p,ll k){
    Z ans = 1;
    while(k){
        if(k % 2 == 1) ans *= p;
        p *= p;
        k /= 2;
    }
    return ans;
}
int n,m;
int a[3005],b[3005];
Z ans[3005];

int eval(int *f,int l,int r,int k){
    int ret = 0;
    for(int pl = l,pr;pl < r;pl = pr){
        pr = pl + 1;
        while(pr < r && (f[pr + 1] - f[pr]) * (f[pr] - f[pr - 1]) > 0) pr++;
        ret += (pr - pl - 1) / k;
    }
    return ret;    
}
Z ssum[2][3005][3005];
int main(){
//    freopen("test.in","r",stdin);
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%d",&a[i]);
    rep(i,1,m) scanf("%d",&b[i]);
    if(max(n,m) > 3000) return 0;
    int sum,cur;
    rep(k,1,n + m - 1){
        rep(i,1,n) fill(ssum[0][i],ssum[0][i] + n + 1,0);
        memset(ssum[1],0,sizeof(ssum[1]));
        rep(l,1,n){
            sum = 0;
            cur = -1;
            ssum[0][1][0] += 1;
            rep(r,l + 1,n){
                if(r > l + 1 && (a[r] - a[r - 1]) * (a[r - 1] - a[r - 2]) < 0){
                    sum += cur / k;
                    cur = 0;
                }else{
                    cur++;
                }
                ssum[0][r - l + 1][sum + cur / k] += 1;
            }
        }
        rep(l,1,m){
            sum = 0;
            cur = -1;
            ssum[1][1][0] += 1;
            rep(r,l + 1,m){
                if(r > l + 1 && (b[r] - b[r - 1]) * (b[r - 1] - b[r - 2]) < 0){
                    sum += cur / k;
                    cur = 0;
                }else{
                    cur++;
                }
                ssum[1][r - l + 1][sum + cur / k] += 1;
            }         
        }
        per(i,m,0){
            rep(j,0,max(n,m)) ssum[1][i][j] += ssum[1][i + 1][j];
        }
        rep(i,0,m){
            rep(j,1,max(n,m)) ssum[1][i][j] += ssum[1][i][j - 1];
        }

        rep(i,1,n){
            rep(j,0,n){
                ans[k + 1] += ssum[0][i][j] * ssum[1][j][i];
            }
        }
//        printf("%d ",ans[k + 1].val());
    }
//    printf("\n");
    per(i,n + m,1) ans[i] -= ans[i - 1];
    rep(i,1,n + m) printf("%d ",ans[i].val());
	return 0;
}

详细

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 7ms
memory: 74496kb

input:

1 1
1
2

output:

0 1 

result:

ok single line: '0 1 '

Test #2:

score: 1
Accepted
time: 3ms
memory: 74488kb

input:

2 1
2 3
1

output:

0 3 0 

result:

ok single line: '0 3 0 '

Test #3:

score: 1
Accepted
time: 7ms
memory: 74316kb

input:

1 3
1
4 2 3

output:

0 6 0 0 

result:

ok single line: '0 6 0 0 '

Test #4:

score: 1
Accepted
time: 8ms
memory: 74372kb

input:

3 4
4 6 7
2 1 3 5

output:

0 60 0 0 0 0 0 

result:

ok single line: '0 60 0 0 0 0 0 '

Test #5:

score: 1
Accepted
time: 31ms
memory: 74320kb

input:

10 10
13 18 7 4 15 1 10 12 5 8
17 20 14 3 16 9 6 2 19 11

output:

0 2741 284 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '0 2741 284 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #6:

score: 1
Accepted
time: 28ms
memory: 74444kb

input:

10 5
5 2 11 1 8 15 12 4 14 3
13 7 10 9 6

output:

0 765 60 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '0 765 60 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #7:

score: 1
Accepted
time: 31ms
memory: 74448kb

input:

9 10
14 7 6 3 1 4 11 16 18
12 10 9 5 2 8 13 15 17 19

output:

0 1592 746 109 28 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '0 1592 746 109 28 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #8:

score: 1
Accepted
time: 34ms
memory: 74452kb

input:

9 10
9 16 15 18 2 14 11 13 5
1 8 7 19 12 17 3 10 4 6

output:

0 2475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '0 2475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #9:

score: 1
Accepted
time: 34ms
memory: 74440kb

input:

10 10
2 4 8 9 10 11 12 14 16 17
1 3 5 6 7 13 15 18 19 20

output:

0 1597 1004 304 100 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '0 1597 1004 304 100 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #2:

score: 1
Accepted

Test #10:

score: 1
Accepted
time: 95ms
memory: 74432kb

input:

30 30
21 60 56 26 50 1 4 52 51 58 34 13 54 59 7 28 33 46 18 39 43 37 32 36 19 25 30 16 38 55
45 23 48 40 2 17 29 27 57 53 12 6 49 15 3 31 9 5 20 44 47 24 11 22 10 42 41 35 8 14

output:

0 149064 63399 3762 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 149064 63399 3762 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #11:

score: 1
Accepted
time: 87ms
memory: 74496kb

input:

26 30
39 46 51 22 6 18 42 56 17 21 12 54 7 33 2 35 23 4 41 31 44 47 38 55 36 25
15 24 30 9 50 48 32 49 26 16 19 34 52 37 29 53 8 1 3 43 45 14 5 11 40 28 20 27 10 13

output:

0 117880 42735 2600 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 117880 42735 2600 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #12:

score: 1
Accepted
time: 92ms
memory: 74364kb

input:

20 30
20 29 4 3 46 9 33 12 34 16 41 23 18 49 8 27 42 1 22 28
2 40 7 47 39 19 5 30 31 21 25 45 17 11 26 38 43 13 24 14 37 15 36 6 48 50 10 32 44 35

output:

0 77108 19422 1120 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 77108 19422 1120 0 0 0 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #13:

score: 1
Accepted
time: 106ms
memory: 74428kb

input:

29 30
45 41 37 36 34 32 21 18 16 15 13 11 7 3 2 9 23 25 31 39 42 46 47 48 52 54 57 58 59
56 55 51 43 40 38 35 28 24 22 14 8 6 4 1 5 10 12 17 19 20 26 27 29 30 33 44 49 50 53

output:

0 49187 82131 32026 15994 9635 5169 4611 1224 678 560 442 324 206 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 49187 82131 32026 15994 9635... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #14:

score: 1
Accepted
time: 103ms
memory: 74384kb

input:

30 29
25 22 38 32 33 1 58 15 52 48 50 34 39 27 40 36 44 19 37 9 31 2 16 8 26 7 56 41 45 12
28 21 54 43 55 17 30 14 20 18 59 46 51 3 35 5 42 29 57 11 47 24 49 23 53 10 13 4 6

output:

0 202275 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 202275 0 0 0 0 0 0 0 0 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #15:

score: 1
Accepted
time: 94ms
memory: 74432kb

input:

30 30
59 56 54 53 48 46 44 43 42 41 40 38 36 33 30 28 27 26 25 24 22 21 17 16 15 10 8 6 4 3
60 58 57 55 52 51 50 49 47 45 39 37 35 34 32 31 29 23 20 19 18 14 13 12 11 9 7 5 2 1

output:

0 44487 87654 35016 17978 10540 6702 4504 3014 2196 1434 1020 780 540 300 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 44487 87654 35016 17978 1054... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #16:

score: 1
Accepted
time: 98ms
memory: 74496kb

input:

30 30
3 49 41 35 33 16 12 17 26 32 60 59 56 50 31 25 9 1 22 23 39 37 34 27 19 6 4 15 11 8
20 29 21 13 7 58 57 54 52 51 48 47 10 28 45 36 14 5 2 38 40 42 44 55 53 46 43 30 24 18

output:

0 79069 85159 28733 17620 3994 1650 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 79069 85159 28733 17620 3994... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #17:

score: 1
Accepted
time: 99ms
memory: 74368kb

input:

30 30
27 4 19 13 31 20 34 38 42 44 47 50 51 52 54 55 59 23 30 32 26 17 12 46 45 41 37 28 5 2
60 58 57 56 49 40 9 10 16 21 35 15 22 6 3 7 53 48 36 29 25 14 11 1 18 33 43 24 39 8

output:

0 96660 78586 24374 11611 1910 3084 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 96660 78586 24374 11611 1910... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #18:

score: 1
Accepted
time: 55ms
memory: 74448kb

input:

27 3
1 2 5 6 7 13 14 15 17 19 20 21 28 29 27 26 25 24 23 22 18 16 12 11 10 9 4
8 3 30

output:

0 579 387 357 309 231 189 108 33 27 21 15 9 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

ok single line: '0 579 387 357 309 231 189 108 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #19:

score: 1
Accepted
time: 102ms
memory: 74380kb

input:

30 30
14 27 51 41 18 38 42 39 7 48 59 43 21 35 52 20 11 44 49 36 5 56 60 17 16 25 37 23 12 28
24 22 3 32 58 45 2 53 54 47 26 46 50 29 8 9 30 19 10 34 40 15 6 31 33 4 1 55 57 13

output:

0 127409 88816 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 127409 88816 0 0 0 0 0 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #20:

score: 1
Accepted
time: 119ms
memory: 74316kb

input:

30 30
31 23 22 12 40 53 60 13 5 1 7 32 45 37 33 26 41 55 56 42 29 18 52 57 58 21 16 11 19 50
49 34 8 4 30 38 47 43 25 15 17 28 36 9 6 3 20 27 46 39 10 2 14 24 59 54 48 35 44 51

output:

0 96399 70758 49068 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 96399 70758 49068 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #3:

score: 1
Accepted

Test #21:

score: 1
Accepted
time: 383ms
memory: 74492kb

input:

100 100
3 185 115 158 149 111 166 94 76 141 167 193 49 11 95 99 97 89 191 98 32 8 20 170 179 63 190 50 4 16 70 75 169 125 178 198 5 71 30 12 128 6 107 62 90 116 39 173 133 31 139 162 144 195 28 160 23 53 55 78 182 153 114 157 46 92 188 43 177 192 124 150 79 146 80 102 7 77 18 82 165 17 15 197 119 14...

output:

0 16086875 8174944 1124681 116000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 16086875 8174944 1124681 116... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #22:

score: 1
Accepted
time: 298ms
memory: 74440kb

input:

100 54
86 71 64 149 76 137 121 126 96 50 42 82 72 100 26 43 104 32 107 128 108 115 27 23 109 54 67 45 143 116 19 12 47 68 6 117 142 61 22 102 144 129 62 93 147 103 30 74 113 85 122 44 135 111 81 139 37 94 127 49 33 133 2 79 120 57 55 87 52 106 29 84 154 4 112 130 132 48 59 119 35 153 9 148 25 141 14...

output:

0 4629539 2737568 132143 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 4629539 2737568 132143 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #23:

score: 1
Accepted
time: 344ms
memory: 74392kb

input:

100 71
66 148 119 86 115 62 145 125 132 109 29 104 56 95 54 140 71 32 166 22 149 120 13 154 18 141 38 31 28 70 130 67 158 42 5 50 146 98 9 55 17 137 90 144 111 89 131 167 74 151 27 110 59 16 14 7 153 126 52 83 92 164 127 168 81 41 87 99 156 117 135 108 142 163 25 118 49 75 47 68 2 94 162 102 84 44 5...

output:

0 8300884 3762855 844061 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 8300884 3762855 844061 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #24:

score: 1
Accepted
time: 365ms
memory: 74448kb

input:

100 99
7 9 13 22 33 34 40 42 43 45 50 51 61 68 69 70 71 72 81 86 97 100 104 105 107 118 124 125 128 129 133 137 139 141 142 145 147 149 153 156 160 161 167 170 173 175 177 180 181 199 198 195 192 191 189 188 187 186 185 183 182 179 171 169 166 164 158 152 148 144 140 136 132 131 117 112 110 109 92 8...

output:

0 1889732 10411401 4330329 2318369 1437285 968805 705312 517114 395243 337291 242681 231301 168782 139223 133827 128431 89652 63153 61195 59237 57279 55321 53363 51405 34769 9452 9054 8656 8258 7860 7462 7064 6666 6268 5870 5472 5074 4676 4278 3880 3482 3084 2686 2288 1890 1492 1094 696 298 0 0 0 0 ...

result:

ok single line: '0 1889732 10411401 4330329 231... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #25:

score: 1
Accepted
time: 392ms
memory: 74500kb

input:

100 99
101 55 159 81 102 94 178 160 198 93 174 73 182 172 189 131 158 23 199 190 191 80 106 19 170 13 121 97 135 3 38 28 44 32 153 110 183 88 130 35 105 36 63 22 119 64 155 2 60 25 43 33 168 12 76 68 154 141 193 9 127 30 139 133 140 14 65 53 92 6 113 95 151 29 148 134 149 143 177 1 107 10 147 137 14...

output:

0 24997500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 24997500 0 0 0 0 0 0 0 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #26:

score: 1
Accepted
time: 417ms
memory: 74340kb

input:

100 100
1 5 7 9 12 14 15 17 19 21 24 26 27 28 30 35 39 41 42 43 44 46 47 48 49 51 52 53 58 59 60 61 62 63 65 67 69 70 73 74 75 78 79 82 83 87 93 97 98 100 102 103 105 106 107 109 110 111 114 116 118 120 121 122 123 125 130 132 133 134 135 137 142 143 146 147 148 149 150 152 153 155 156 161 162 163 1...

output:

0 1661452 10598504 4426144 2372720 1469860 995850 716816 538654 418320 332940 270772 223580 186638 158720 134780 117110 100206 88486 77918 67350 59692 53974 48256 42538 36820 33062 30480 27898 25316 22734 20152 17570 14988 13000 12200 11400 10600 9800 9000 8200 7400 6600 5800 5000 4200 3400 2600 180...

result:

ok single line: '0 1661452 10598504 4426144 237... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #27:

score: 1
Accepted
time: 478ms
memory: 74448kb

input:

100 100
12 13 16 28 36 91 120 133 144 74 10 14 34 62 81 115 131 167 164 132 111 73 45 31 161 160 141 138 136 117 87 85 61 50 47 2 4 24 37 107 82 77 35 46 124 151 170 171 137 130 114 112 65 59 44 27 29 52 66 70 78 106 116 126 145 153 154 200 198 197 195 194 188 186 182 176 175 174 125 32 15 19 71 113...

output:

0 4211756 10732152 4286607 2541146 914255 1147024 517389 587437 150179 115092 168663 130800 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 4211756 10732152 4286607 254... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #28:

score: 1
Accepted
time: 510ms
memory: 74452kb

input:

100 100
50 44 45 5 33 49 4 24 48 52 61 81 93 100 106 14 13 2 41 171 168 165 162 160 155 146 142 131 126 122 121 120 116 108 90 88 87 86 67 58 7 12 1 43 111 56 85 79 77 69 65 51 40 28 18 15 10 21 27 29 30 68 80 84 92 97 98 102 113 130 132 133 143 144 145 148 149 159 163 167 170 172 175 176 179 180 18...

output:

0 4530465 10558635 3889978 2255039 1214068 631888 640605 376928 288176 438617 198290 60691 58614 183879 25052 18839 18243 17647 17051 16455 57640 5700 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 4530465 10558635 3889978 225... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #29:

score: 1
Accepted
time: 209ms
memory: 74448kb

input:

97 3
2 6 8 11 13 17 18 22 24 26 29 32 34 35 40 41 45 49 50 51 52 54 56 58 60 62 64 70 71 72 75 76 77 82 85 86 87 88 90 91 92 93 94 95 96 97 98 99 100 84 83 81 80 79 78 74 73 69 68 67 66 65 63 61 59 57 55 53 48 47 46 43 42 39 38 37 36 33 30 28 27 25 23 21 20 19 16 15 14 12 10 9 7 5 4 3 1
89 31 44

output:

0 2119 1507 1477 1447 1417 1387 1357 1327 1297 1267 1237 1207 1085 1071 1057 1043 735 721 707 693 679 665 651 637 141 135 129 123 117 111 105 99 93 87 81 75 69 63 57 51 45 39 33 27 21 15 9 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 2119 1507 1477 1447 1417 138... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #30:

score: 1
Accepted
time: 459ms
memory: 74432kb

input:

100 100
26 61 187 179 170 177 181 50 19 57 81 37 8 13 94 60 40 51 104 100 84 108 154 82 71 178 185 99 14 134 160 52 49 68 135 45 5 46 169 158 18 33 123 85 73 76 175 157 106 137 193 191 145 164 189 67 23 95 141 130 2 63 151 75 58 89 171 101 93 148 153 91 24 43 87 25 16 149 188 182 62 97 136 120 119 1...

output:

0 12061604 13440896 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 12061604 13440896 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #31:

score: 1
Accepted
time: 422ms
memory: 74448kb

input:

100 100
28 49 51 121 107 96 40 76 160 166 164 57 10 29 35 130 104 100 46 92 127 199 131 108 102 158 187 198 146 103 2 21 48 177 165 142 81 143 157 188 53 23 12 38 88 189 180 176 149 162 168 197 196 41 5 30 69 136 27 11 4 7 65 140 123 32 17 110 137 173 153 114 112 115 159 191 167 77 19 63 79 184 178 ...

output:

0 8144636 8536056 8821808 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 8144636 8536056 8821808 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #4:

score: 1
Accepted

Test #32:

score: 1
Accepted
time: 1787ms
memory: 74392kb

input:

300 300
97 322 293 313 283 13 27 353 474 32 562 75 10 317 136 482 81 309 584 138 437 48 159 339 334 356 526 357 1 352 235 242 456 461 219 66 436 565 559 284 112 20 111 23 384 51 514 134 462 124 400 261 216 76 171 202 239 238 333 179 545 527 407 539 418 588 248 440 427 376 549 15 411 355 299 365 9 12...

output:

0 264114717 638832402 110629026 24946348 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 264114717 638832402 11062902... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #33:

score: 1
Accepted
time: 1452ms
memory: 74400kb

input:

243 300
182 523 513 416 89 371 114 348 361 204 484 297 148 41 379 390 507 263 541 135 172 468 139 512 391 224 71 227 489 428 314 447 306 236 251 16 136 339 104 328 214 503 385 223 349 445 151 278 217 369 408 284 294 111 528 427 189 141 438 305 510 21 208 487 44 482 486 520 4 72 495 511 471 5 156 68 ...

output:

0 825574111 415747196 86898634 7219850 3077109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 825574111 415747196 86898634... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #34:

score: 1
Accepted
time: 1811ms
memory: 74496kb

input:

258 300
544 73 24 312 326 16 277 374 445 429 86 309 466 475 235 4 35 77 294 292 377 289 439 32 219 233 74 410 174 248 29 474 325 359 360 19 339 255 398 361 193 149 296 168 221 282 60 515 70 263 136 82 80 319 412 79 478 114 486 380 40 204 177 249 502 98 192 491 501 133 436 118 100 507 352 329 484 454...

output:

0 856929210 498806907 123842325 22675308 6252900 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 856929210 498806907 12384232... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #35:

score: 1
Accepted
time: 1837ms
memory: 74504kb

input:

299 300
2 6 13 14 16 21 25 28 31 34 35 38 47 48 57 58 71 88 90 96 103 133 147 148 154 156 162 163 165 175 178 180 181 191 192 196 198 199 200 201 202 206 210 222 223 229 235 236 238 239 241 242 245 250 252 257 264 265 266 272 273 289 292 298 301 302 307 313 321 325 326 334 339 342 346 349 354 356 35...

output:

0 51511682 844264201 354921351 191150672 119059120 81136411 58731939 44520779 34862685 28185071 22876625 19234107 16296614 14013018 12353551 10387636 9419994 8261449 7552356 6462077 6299509 5320464 4818491 4712273 4474711 3472826 3408296 3343766 3279236 3082691 2287081 2251701 2216321 2180941 214556...

result:

ok single line: '0 51511682 844264201 354921351... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #36:

score: 1
Accepted
time: 1801ms
memory: 74388kb

input:

299 300
42 309 296 324 29 487 354 490 370 455 449 453 69 428 368 543 105 131 81 508 446 451 75 85 80 399 267 277 93 158 55 196 135 504 448 599 536 576 61 315 299 466 209 348 127 376 294 519 28 220 83 401 82 99 34 517 197 450 38 572 73 343 10 221 211 224 31 292 198 284 121 250 24 247 217 379 246 278 ...

output:

0 24977486 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 24977486 0 0 0 0 0 0 0 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #37:

score: 1
Accepted
time: 1972ms
memory: 74396kb

input:

300 300
1 2 7 8 10 14 15 16 17 20 21 26 31 41 42 44 45 46 47 49 50 52 53 54 55 56 57 59 60 65 66 70 75 76 77 79 85 92 93 94 95 96 99 100 102 103 105 107 114 115 117 118 121 122 123 125 126 127 130 132 133 136 137 138 142 144 146 148 149 151 152 156 157 158 160 161 162 163 164 166 167 170 171 173 177...

output:

0 44954352 849135504 357416106 192580458 119941560 81759912 59257828 44895380 35172456 28286004 23233590 19413606 16459894 14125790 12249750 10720742 9458488 8402250 7510630 6753320 6102642 5532970 5046818 4614390 4234560 3899970 3603660 3328302 3100668 2874780 2681012 2513524 2346036 2190854 206907...

result:

ok single line: '0 44954352 849135504 357416106... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #38:

score: 1
Accepted
time: 1974ms
memory: 74504kb

input:

300 300
3 65 74 169 225 242 261 267 599 597 590 589 588 585 583 580 577 569 565 541 534 424 419 415 334 323 266 162 153 144 130 67 75 122 129 155 228 240 264 280 473 464 427 384 365 260 259 252 231 203 180 140 120 106 52 59 132 196 222 226 249 250 271 287 306 310 342 351 374 389 395 398 538 553 579 ...

output:

0 154017713 859071682 353851604 189668929 112891391 90841023 48970744 42957903 28117415 26963047 23077864 30058747 6690949 7018139 8713944 9107555 12217832 6616183 4484042 8796675 7946662 2746757 3695700 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 154017713 859071682 35385160... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #39:

score: 1
Accepted
time: 1995ms
memory: 74436kb

input:

300 300
21 66 76 116 137 145 162 172 267 269 286 296 297 299 318 329 336 337 339 346 375 388 393 404 406 407 411 412 419 429 431 437 443 450 459 468 471 472 480 482 487 498 499 500 503 44 57 82 98 101 115 132 148 150 151 161 168 225 230 241 251 262 301 307 315 343 364 365 387 392 401 402 413 416 425...

output:

0 178761810 848327720 356480234 172155613 111365604 74158895 49106032 44735288 29970377 23503058 25052358 12437347 10609228 8287874 18108532 3530279 10832000 2734409 4590929 5169592 6800434 6990689 1740314 1378499 6117664 912233 903590 894947 886304 7669129 709623 702158 3555766 645133 366025 362433...

result:

ok single line: '0 178761810 848327720 35648023... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #40:

score: 1
Accepted
time: 920ms
memory: 74448kb

input:

297 3
289 287 278 277 276 275 274 270 268 267 263 262 260 258 257 256 255 254 252 251 250 247 244 240 238 236 235 233 232 231 230 227 225 221 220 214 209 208 206 205 203 201 195 193 191 188 187 185 183 180 179 177 174 173 172 171 169 167 166 162 161 160 157 156 153 152 151 146 145 144 143 141 140 13...

output:

0 6519 4707 4677 4647 4617 4587 4557 4527 4497 4467 4437 4407 4377 4347 4317 4287 4257 4227 4197 4167 4137 4107 4077 4047 4017 3987 3957 3927 3897 3867 3837 3807 3777 3747 3717 3687 3657 3335 3321 3307 3293 3279 3265 3251 3237 3223 3209 3195 3181 2571 2259 2245 2231 2217 2203 2189 2175 2161 2147 213...

result:

ok single line: '0 6519 4707 4677 4647 4617 458... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #41:

score: 1
Accepted
time: 1903ms
memory: 74376kb

input:

297 300
357 134 46 201 563 430 380 507 591 247 176 365 469 49 1 536 569 237 76 302 455 381 263 282 531 489 14 223 523 192 53 160 514 471 462 483 521 309 228 334 567 556 425 464 586 568 501 518 527 399 122 431 496 348 339 414 498 138 62 105 405 259 84 163 406 382 314 321 450 415 366 493 511 180 58 11...

output:

0 871042397 126980546 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 871042397 126980546 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Test #42:

score: 1
Accepted
time: 2042ms
memory: 74372kb

input:

297 298
175 179 205 411 410 323 321 435 456 459 245 125 52 61 496 501 393 379 141 280 282 539 521 442 50 118 154 470 348 259 81 200 342 378 137 14 5 22 408 441 224 157 70 340 444 550 504 365 356 527 567 575 394 161 49 167 423 576 164 64 41 111 318 528 440 439 271 373 502 507 343 195 32 42 69 465 269...

output:

0 551908274 658779572 760827557 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 single line: '0 551908274 658779572 76082755... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #5:

score: 0
Time Limit Exceeded

Test #43:

score: 0
Time Limit Exceeded

input:

2000 2000
762 3148 1563 2539 1799 983 3993 1082 2912 3178 1908 2990 16 886 2973 823 913 243 357 850 2486 1588 2649 1893 1634 3691 150 996 3789 2922 2393 577 2316 924 3674 3636 910 2406 1483 1212 579 2442 1875 918 2039 928 2009 920 462 3898 1764 1592 1220 3893 1602 772 3485 1640 1940 2409 994 3201 62...

output:


result:


Subtask #6:

score: 0
Runtime Error

Test #55:

score: 0
Runtime Error

input:

8000 8000
7244 4104 4116 4733 1865 12849 14465 11794 1095 7219 5206 2781 11617 6866 9595 11983 14469 13258 2346 10847 5429 3414 4293 15825 10314 9643 14412 9550 6406 7816 13719 15736 5333 15692 12756 4329 2709 5284 5261 1707 11238 4301 13797 2131 12768 7126 9864 3229 3785 4314 8719 1117 646 8153 111...

output:


result:


Subtask #7:

score: 0
Runtime Error

Test #68:

score: 0
Runtime Error

input:

70000 70000
65040 83209 46810 43228 58294 97341 24577 26778 64585 34392 121492 59033 52566 63751 20036 135689 72762 109553 67967 51787 107523 120416 95354 49900 60667 110736 115814 16626 34683 37257 119483 91814 68147 131865 33293 114111 65264 122197 57479 111482 75492 84033 133075 73321 7539 47697 ...

output:


result:


Subtask #8:

score: 0
Runtime Error

Test #82:

score: 0
Runtime Error

input:

150000 150000
58983 100778 109945 294477 253435 1447 4311 110912 171122 212851 165373 102223 98625 274188 43059 196284 13184 232675 189091 37409 150201 227081 221065 161136 37343 47901 56955 197030 149843 137335 85230 291418 55155 84454 284046 96806 7342 94155 189355 60618 87506 281679 180207 125356...

output:


result:


Subtask #9:

score: 0
Runtime Error

Test #97:

score: 0
Runtime Error

input:

230000 230000
53349 24839 147164 179787 169500 138524 104308 71283 404918 183895 337401 419461 119619 389931 304997 360563 177306 435849 94845 192364 358356 159738 442086 88126 354608 167743 320160 221916 402274 207329 178240 316555 328700 13950 214332 286314 232082 56917 406912 123163 219788 153687...

output:


result:


Subtask #10:

score: 0
Runtime Error

Test #112:

score: 0
Runtime Error

input:

300000 300000
416773 186118 31247 38672 389294 339767 320108 250609 228574 232436 344414 316497 334835 318936 3172 393368 210300 145194 50617 423649 504469 6918 54400 485308 99748 556889 171790 488017 290307 560629 126324 57741 457051 257487 336091 524134 571207 573790 18672 361275 414336 343166 314...

output:


result: