QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515927#7845. Fast ForwardfengAC ✓407ms409468kbC++201.3kb2024-08-12 11:39:112024-08-12 11:39:11

Judging History

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

  • [2024-08-12 11:39:11]
  • 评测
  • 测评结果:AC
  • 用时:407ms
  • 内存:409468kb
  • [2024-08-12 11:39:11]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define ll long long
#define PII std::pair<int,int>
using namespace std;
const int maxn = 2e6 + 5;
int nex[maxn][25];
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(2);
    int n, c; cin >> n >> c;
    int dn = n * 2;
    vector<int> d(dn + 1);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        d[n + i] = d[i];
    }
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += d[i];
    }
    if (c >= sum) {
        for (int i = 0; i < n; ++i) {
            cout << "0" << " ";
        }
        return 0;
    }
    int l = 0, r = 0;
    sum = 0;
    while (l < dn) {
        while (r < dn && sum < c) sum += d[r++];
        nex[l][0] = r;
        sum -= d[l++];
    }

    for (int j = 0; j <= 20; ++j) nex[dn][j] = dn;

    for (int i = dn - 1; i >= 0; --i) {
        for (int j = 1; j <= 20; ++j) {
            nex[i][j] = nex[nex[i][j - 1]][j - 1];
        }
    }
    for (int i = 0; i < n; ++i) {
        int ans = 0, cur = i;
        for (int j = 20; j >= 0; --j) {
            if (nex[cur][j] - i < n) {
                ans |= 1 << j;
                cur = nex[cur][j];
            }
        }
        cout << ans << " ";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 7
1 1 1 1 1 1 1

output:

0 0 0 0 0 0 0 

result:

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

Test #2:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

3 3
1 1 3

output:

0 1 1 

result:

ok single line: '0 1 1 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

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

output:

5 4 5 4 4 5 4 4 5 4 

result:

ok single line: '5 4 5 4 4 5 4 4 5 4 '

Test #4:

score: 0
Accepted
time: 205ms
memory: 409468kb

input:

1000000 22867
553 901 645 485 940 745 166 365 357 935 102 534 812 329 56 650 100 992 528 829 755 128 190 916 245 942 132 359 367 562 636 77 62 562 404 487 545 298 71 697 784 523 957 383 332 650 636 822 245 379 792 605 239 69 723 867 925 308 511 975 808 341 341 125 940 833 810 282 567 754 893 59 618 ...

output:

21589 21589 21589 21589 21589 21589 21589 21589 21589 21590 21590 21590 21590 21590 21590 21590 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 21589 ...

result:

ok single line: '21589 21589 21589 21589 21589 ... 21589 21589 21589 21589 21589 '

Test #5:

score: 0
Accepted
time: 55ms
memory: 18788kb

input:

1000000 1000000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok single line: '0 0 0 0 0 0 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 #6:

score: 0
Accepted
time: 168ms
memory: 409400kb

input:

1000000 1000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok single line: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 '

Test #7:

score: 0
Accepted
time: 407ms
memory: 409388kb

input:

1000000 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999 999999...

result:

ok single line: '999999 999999 999999 999999 99...99 999999 999999 999999 999999 '

Test #8:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

10 3
8 2 4 3 6 3 3 7 9 8

output:

8 8 9 8 8 8 8 8 8 8 

result:

ok single line: '8 8 9 8 8 8 8 8 8 8 '

Test #9:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

100 8
4 4 1 1 1 3 1 2 3 3 2 3 5 2 1 3 2 1 1 1 5 2 2 4 3 5 4 2 3 3 3 3 2 5 2 2 4 1 2 5 3 4 5 3 3 1 4 5 5 1 2 4 3 1 1 2 3 1 5 5 4 2 3 5 5 1 1 5 3 4 3 4 2 1 2 3 4 1 5 1 1 3 1 5 1 4 3 4 1 2 4 3 4 2 5 4 4 1 2 4

output:

30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 30 31 30 30 30 30 30 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 30 30 31 30 30 31 31 30 30 31 30 30 31 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 

result:

ok single line: '30 30 30 31 30 30 30 30 30 30 ... 30 30 30 30 30 30 30 30 30 30 '

Test #10:

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

input:

1000 12
24 12 12 8 14 20 5 20 11 4 25 23 16 24 6 7 14 7 11 6 7 16 25 5 19 8 8 20 3 10 9 8 1 25 9 2 20 2 17 22 7 5 21 25 7 23 15 24 4 17 2 1 20 10 13 19 4 19 9 14 11 7 13 4 19 12 23 19 6 20 20 17 5 25 8 15 24 18 16 2 12 23 20 10 12 19 7 23 3 25 1 16 9 6 4 6 4 10 4 1 17 12 15 18 13 8 19 22 10 25 3 16 ...

output:

658 657 657 657 658 657 657 658 657 657 657 657 657 657 657 657 657 657 657 657 657 657 657 657 658 657 657 657 657 657 657 657 657 658 657 658 658 657 658 657 657 657 657 657 657 658 657 657 657 658 657 658 658 657 658 657 657 658 657 658 657 657 657 657 658 657 657 657 657 658 657 657 657 658 657 ...

result:

ok single line: '658 657 657 657 658 657 657 65...57 658 657 658 657 657 658 657 '

Test #11:

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

input:

1000 37
44 94 6 47 73 16 60 49 73 62 97 28 21 6 70 89 33 10 49 55 8 2 72 29 4 29 91 17 94 100 36 43 83 3 22 6 1 75 50 95 49 12 53 35 95 9 3 92 84 26 77 93 60 40 96 29 19 25 9 35 41 5 6 88 36 27 95 88 22 79 14 63 24 67 72 61 51 3 59 65 50 63 12 13 73 18 14 50 51 2 7 71 10 44 79 38 84 23 100 63 58 67 ...

output:

697 696 696 697 696 696 697 696 696 696 696 696 696 696 697 696 696 696 696 696 696 697 697 696 696 696 696 696 697 696 696 697 696 696 697 697 697 697 696 696 696 696 697 696 697 696 697 697 696 696 697 696 696 696 696 696 697 696 697 696 696 696 697 697 696 696 696 696 696 697 696 697 696 697 696 ...

result:

ok single line: '697 696 696 697 696 696 697 69...96 697 696 696 696 696 696 696 '

Test #12:

score: 0
Accepted
time: 337ms
memory: 409272kb

input:

1000000 65
64 91 62 47 79 84 60 12 62 43 98 90 51 55 80 11 75 92 56 95 18 34 99 3 93 48 82 75 84 86 1 21 25 22 48 76 4 13 92 72 42 65 56 29 43 56 42 5 36 27 38 73 9 5 97 12 68 79 77 82 17 66 84 35 9 28 70 4 64 36 82 91 13 72 90 7 65 70 82 87 24 8 72 57 61 68 80 44 39 43 38 9 98 75 54 34 53 25 99 91 ...

output:

529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529609 529610 529609 529609 529610 529609 529610 529610 529609 529610 529609 529610 529609 529609 529609 529609 529610 529610 529610 529609 529610 529609 529610 529610 529609 529609 529610 529609...

result:

ok single line: '529609 529609 529609 529609 52...10 529609 529609 529609 529610 '

Test #13:

score: 0
Accepted
time: 205ms
memory: 409468kb

input:

1000000 990
4 89 22 24 73 63 81 78 71 99 15 16 61 5 33 5 69 87 56 57 60 4 80 76 54 64 77 31 43 63 87 3 6 54 17 13 17 35 95 44 6 15 71 4 7 41 65 43 66 79 59 45 43 27 27 84 82 49 21 71 51 15 90 32 82 30 49 62 95 53 42 27 92 97 98 28 29 22 35 75 68 43 78 26 34 13 16 28 55 22 56 96 26 60 2 16 9 65 89 48...

output:

49374 49374 49374 49374 49374 49373 49373 49373 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49373 49373 49373 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49374 49373 ...

result:

ok single line: '49374 49374 49374 49374 49374 ... 49374 49374 49374 49374 49374 '

Test #14:

score: 0
Accepted
time: 385ms
memory: 409456kb

input:

1000000 114
667 871 367 86 37 432 705 325 483 395 779 392 262 847 377 319 155 671 523 29 439 943 694 795 118 246 644 369 302 103 199 846 748 826 183 256 408 947 628 670 257 219 570 840 141 936 348 901 787 138 665 886 489 339 678 819 212 406 161 974 396 752 491 323 525 319 763 524 847 19 70 505 165 2...

output:

893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893285 893284 893284 893284 893284 893284 893284 893284 893284 893284 893285 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284 893284...

result:

ok single line: '893284 893284 893284 893284 89...84 893284 893284 893284 893284 '

Test #15:

score: 0
Accepted
time: 233ms
memory: 409440kb

input:

1000000 4739
474 560 955 876 736 103 890 75 806 270 824 498 94 754 955 260 597 309 885 227 709 268 926 673 166 389 729 395 305 34 224 736 263 605 773 435 399 969 416 93 909 355 71 174 964 496 219 157 500 930 36 745 505 189 989 827 181 940 743 860 12 661 385 793 43 216 362 516 415 74 154 594 909 780 ...

output:

98635 98635 98634 98634 98634 98635 98635 98635 98635 98635 98635 98634 98634 98634 98634 98635 98635 98635 98635 98635 98634 98634 98634 98634 98635 98635 98635 98635 98635 98635 98635 98634 98634 98634 98634 98634 98635 98635 98635 98635 98635 98634 98634 98634 98634 98634 98635 98635 98635 98635 ...

result:

ok single line: '98635 98635 98634 98634 98634 ... 98634 98634 98634 98635 98635 '