QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625809#8410. Splatanie ciągów [A]chenxinyang20060 403ms74500kbC++205.0kb2024-10-09 21:07:142024-10-09 21:07:14

Judging History

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

  • [2024-10-09 21:07:14]
  • 评测
  • 测评结果:0
  • 用时:403ms
  • 内存:74500kb
  • [2024-10-09 21:07:14]
  • 提交

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);
        rep(i,0,m) fill(ssum[1][i],ssum[1][i] + m + 1,0);
        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,n){
                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,m) ssum[1][i][j] += ssum[1][i + 1][j];
        }
        rep(i,0,m){
            rep(j,1,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];
        }
    }
    per(i,n + m,1) ans[i] -= ans[i - 1];
    rep(i,1,n + m) printf("%d ",ans[i].val());
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

1 1
1
2

output:

0 1 

result:

ok single line: '0 1 '

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 74500kb

input:

2 1
2 3
1

output:

0 4 2 

result:

wrong answer 1st lines differ - expected: '0 3 0', found: '0 4 2 '

Subtask #2:

score: 0
Wrong Answer

Test #10:

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

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: 0
Wrong Answer
time: 0ms
memory: 74396kb

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 93034 30011 1560 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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:

wrong answer 1st lines differ - expected: '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', found: '0 93034 30011 1560 0 0 0 0 0 0... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '

Subtask #3:

score: 0
Wrong Answer

Test #21:

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

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: 0
Wrong Answer
time: 9ms
memory: 74388kb

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 6671316 3673623 785378 394370 284538 248246 227314 215005 206391 200347 196825 193973 190631 189837 189043 187358 185574 185374 185174 184974 184774 184574 184374 183274 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 182574 18...

result:

wrong answer 1st lines differ - expected: '0 4629539 2737568 132143 0 0 0...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 6671316 3673623 785378 39437...74 182574 182574 182574 182574 '

Subtask #4:

score: 0
Wrong Answer

Test #32:

score: 1
Accepted
time: 403ms
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: 0
Wrong Answer
time: 288ms
memory: 74324kb

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 554619442 264784157 57708196 3170285 293058 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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:

wrong answer 1st lines differ - expected: '0 825574111 415747196 86898634...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '0 554619442 264784157 57708196... 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: