QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116518#1855. Minimal Cyclic ShiftLinshey#AC ✓229ms20936kbC++141.9kb2023-06-29 13:53:432023-06-29 13:53:45

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-29 13:53:45]
  • 评测
  • 测评结果:AC
  • 用时:229ms
  • 内存:20936kb
  • [2023-06-29 13:53:43]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std; const int maxn = 1e5 + 5, mod = 998244353; typedef long long ll;

int n, a[maxn];

vector<pair<int, int> > D[maxn];

int inv[maxn], p26[maxn];

int main()
{
    scanf("%d", &n);
    if (n == 1) return 0 * puts("1");
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    for (int i = 1; i < maxn; i++) for (int j = i; j < maxn; j += i) D[j].push_back({ i, 0 });
    for (int i = (inv[1] = 1) + 1; i < maxn; i++) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
    // cerr << inv[2] << ' ' << inv[3] << endl;
    for (int i = p26[0] = 1; i < maxn; i++) p26[i] = (ll)p26[i - 1] * inv[26] % mod;
    for (int i = 1, A; i < maxn; i++)
    {
        for (auto &e : D[i]) e.second = p26[i - e.first];
        for (auto e : D[i]) for (auto &E : D[i]) if (E.first != e.first && E.first % e.first == 0) E.second = (E.second - e.second) % mod;
        int s = 0;
        for (auto e : D[i]) s = (s + e.second) % mod;
        // if ((s - 1) % mod != 0)
        // {
        //     cerr << i << endl;
        //     cerr << s << endl;
        // }
        // assert((s - 1) % mod == 0);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int A = a[i], B = a[i % n + 1], C = 0, E = 0;
        // cerr << A << ' ' << B << endl;
        auto x = D[A].begin(), y = D[B].begin();
        for (; x != D[A].end() || y != D[B].end(); )
        {
            if (y == D[B].end() || (x != D[A].end() && x->first <= y->first))
            {
                ans = (ans + (ll)C * inv[x->first] % mod * x->second) % mod;
                E = (E + x->second) % mod;
                x++;
            }
            else
            {
                ans = (ans + (ll)E * inv[y->first] % mod * y->second) % mod;
                C = (C + y->second) % mod;
                y++;
            }
        }
    }
    return 0 * printf("%d\n", (ans + mod) % mod);
}

详细

Test #1:

score: 100
Accepted
time: 115ms
memory: 20368kb

input:

5
3 1 5 2 4

output:

727907401

result:

ok single line: '727907401'

Test #2:

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

input:

1
100000

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 145ms
memory: 20652kb

input:

86767
35422 24898 32532 92988 84636 99872 57831 31700 47597 79017 25316 96560 4822 31820 62125 8873 31377 38988 12468 71596 52652 40575 1313 82552 37864 96176 34224 84035 10267 29886 57968 31414 95022 61051 97957 89292 9248 89389 23526 19511 12610 95760 86463 65531 43001 40017 88433 26385 4384 91445...

output:

878054961

result:

ok single line: '878054961'

Test #4:

score: 0
Accepted
time: 146ms
memory: 20532kb

input:

55721
51563 5451 94713 9537 30709 63343 41819 65855 51779 39457 85060 96650 74359 93631 10042 80788 11639 69710 76709 68048 33133 23893 75696 96409 23880 14590 91789 74156 10137 49112 35534 41001 71159 63159 35661 91318 39323 76627 89445 35612 30725 94245 20918 99528 36789 86829 79973 84299 146 7185...

output:

91462762

result:

ok single line: '91462762'

Test #5:

score: 0
Accepted
time: 144ms
memory: 20528kb

input:

56074
407 10197 24191 58791 9486 68030 25807 11 88665 32600 12100 29445 33496 96658 57959 28510 83389 67729 40950 55989 80911 31402 17375 42970 99496 8811 8138 88468 10007 92530 21612 83292 81887 97972 62965 58752 36694 96568 46851 75905 91943 60026 88076 57717 97872 936 71513 74917 52805 60776 3187...

output:

602599501

result:

ok single line: '602599501'

Test #6:

score: 0
Accepted
time: 115ms
memory: 20332kb

input:

82
518 71 971 121 862 967 607 138 754 513 337 499 873 337 387 647 917 76 417 1000 12 703 826 356 728 984 227 371 864 387 196 251 565 54 672 148 390 5 50 349 772 375 131 885 790 158 269 994 215 155 323 310 11 393 718 20 101 501 450 216 212 508 854 76 162 181 320 916 852 779 967 659 676 620 263 588 26...

output:

166275963

result:

ok single line: '166275963'

Test #7:

score: 0
Accepted
time: 124ms
memory: 20552kb

input:

18
171 816 449 375 934 950 299 702 232 657 81 885 306 660 304 369 371 798

output:

991165057

result:

ok single line: '991165057'

Test #8:

score: 0
Accepted
time: 127ms
memory: 20312kb

input:

28
311 74 927 732 711 126 583 857 118 97 928 975 843 175 221 284 929 816 602 689 863 721 888 478 953 722 141 804

output:

93898560

result:

ok single line: '93898560'

Test #9:

score: 0
Accepted
time: 121ms
memory: 20264kb

input:

38
155 820 596 986 976 813 571 13 301 832 376 769 276 498 138 414 679 834 651 142 449 39 759 527 865 943 1 924 67 257 815 228 862 980 281 42 102 717

output:

974161669

result:

ok single line: '974161669'

Test #10:

score: 0
Accepted
time: 118ms
memory: 20552kb

input:

75469
67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518 72013 20351 78137 67238 70557 16596 79890 56227 1548 62143 71384 92585 80165 81054 2533 42745 18675 3893 37815 82998 33577 43689 38771 91177 48955 80996 59136 61438 3714 78549 97960 82533 33405 69133 63866 95761 2212...

output:

348777940

result:

ok single line: '348777940'

Test #11:

score: 0
Accepted
time: 151ms
memory: 20784kb

input:

94424
83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336 92460 50051 47500 1279 80836 43639 36708 9057 3822 17945 2793 74386 5915 25357 42615 37901 14164 55915 26431 68390 38289 97693 88548 3489 71107 99429 79552 69495 13003 56148 43616 80216 60673 54484 48420 35236 50...

output:

629399843

result:

ok single line: '629399843'

Test #12:

score: 0
Accepted
time: 146ms
memory: 20616kb

input:

63378
32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082 97774 51954 99297 53589 31579 60294 16567 78205 31802 13002 68607 63480 39669 9781 57127 67538 65502 2567 3202 75993 32423 51327 99238 28514 48233 64963 43788 47458 90145 61596 27028 84917 12398 76887 1564...

output:

26347638

result:

ok single line: '26347638'

Test #13:

score: 0
Accepted
time: 145ms
memory: 20684kb

input:

95130
24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688 99512 30019 50534 28032 8072 67180 19884 45659 55914 30124 12533 97086 9652 546 10512 40497 45999 5311 3298 99857 48698 86476 61728 55822 58885 9569 14616 48334 89975 49647 649 78824 29545 61464 12773...

output:

855877739

result:

ok single line: '855877739'

Test #14:

score: 0
Accepted
time: 138ms
memory: 20756kb

input:

64084
73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967 28037 47479 91780 55850 74689 18459 92220 41930 24345 4690 44102 9522 87068 96591 25892 22136 31612 41002 34586 78773 73713 19135 96115 44296 75350 49070 39227 83763 63755 24893 36738 58012 5038...

output:

417509537

result:

ok single line: '417509537'

Test #15:

score: 0
Accepted
time: 133ms
memory: 20568kb

input:

64437
55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759 87527 79721 46731 14903 92843 38781 52138 18566 62255 25710 9392 30486 74157 35479 65568 33721 11410 69316 8848 93655 85054 44920 62410 49643 7717 73223 44847 43270 16433 27356 77967 962...

output:

605645910

result:

ok single line: '605645910'

Test #16:

score: 0
Accepted
time: 129ms
memory: 20692kb

input:

98557
88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499 99500 54572 54419 33657 43179 61234 29965 91136 37826 26886 6880 64913 90362 85934 53747 40219 14676 46017 62847 87713 7556 37069 40466 17625 63376 62673 63213 7789 40149 2948 31686 ...

output:

496339968

result:

ok single line: '496339968'

Test #17:

score: 0
Accepted
time: 208ms
memory: 20700kb

input:

100000
92400 65520 65520 90720 98280 90720 92400 90720 83160 75600 55440 95040 98280 95760 95040 75600 90720 65520 95760 95040 95040 92400 90720 75600 95040 75600 95760 92400 83160 92400 83160 65520 75600 75600 95760 95040 83160 90720 85680 83160 65520 65520 55440 90720 65520 90720 65520 90720 95040...

output:

994389174

result:

ok single line: '994389174'

Test #18:

score: 0
Accepted
time: 220ms
memory: 20696kb

input:

100000
90720 85680 95760 95760 85680 83160 75600 65520 65520 95040 55440 83160 83160 75600 95760 95040 65520 98280 83160 65520 75600 95760 75600 95760 92400 90720 92400 92400 90720 85680 92400 95040 83160 98280 92400 95040 90720 95040 83160 90720 83160 75600 95040 98280 83160 85680 65520 98280 55440...

output:

774988411

result:

ok single line: '774988411'

Test #19:

score: 0
Accepted
time: 225ms
memory: 20896kb

input:

100000
55440 83160 55440 55440 90720 83160 85680 85680 98280 95760 75600 83160 83160 55440 92400 83160 98280 95040 98280 95760 90720 55440 55440 85680 55440 85680 98280 98280 98280 65520 75600 55440 55440 65520 75600 65520 83160 83160 65520 75600 83160 98280 92400 95040 95040 83160 90720 95760 75600...

output:

944180242

result:

ok single line: '944180242'

Test #20:

score: 0
Accepted
time: 220ms
memory: 20692kb

input:

100000
55440 55440 75600 92400 95040 55440 75600 85680 65520 95760 95040 90720 90720 85680 55440 98280 98280 95040 75600 95040 98280 95040 92400 98280 90720 55440 83160 95760 98280 55440 98280 75600 95760 83160 83160 65520 95760 55440 95040 98280 55440 85680 75600 95760 85680 95760 90720 98280 98280...

output:

228240608

result:

ok single line: '228240608'

Test #21:

score: 0
Accepted
time: 229ms
memory: 20700kb

input:

100000
95040 98280 75600 85680 83160 92400 95040 65520 55440 75600 85680 95760 83160 65520 85680 90720 85680 75600 95040 95040 98280 65520 92400 92400 65520 83160 95760 90720 92400 55440 65520 92400 65520 95760 85680 90720 95760 90720 95040 65520 55440 98280 98280 75600 98280 55440 90720 65520 98280...

output:

202421813

result:

ok single line: '202421813'

Test #22:

score: 0
Accepted
time: 226ms
memory: 20692kb

input:

100000
83160 98280 98280 98280 98280 83160 83160 98280 83160 83160 98280 98280 98280 98280 98280 83160 83160 83160 98280 98280 98280 98280 98280 98280 98280 98280 83160 83160 83160 98280 83160 98280 83160 83160 83160 98280 83160 83160 98280 83160 83160 83160 98280 83160 98280 83160 98280 98280 83160...

output:

245057894

result:

ok single line: '245057894'

Test #23:

score: 0
Accepted
time: 212ms
memory: 20936kb

input:

100000
98280 83160 98280 98280 83160 98280 83160 83160 83160 83160 98280 98280 98280 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 98280 98280 83160 83160 98280 83160 83160 83160 98280 83160 83160 98280 83160 83160 98280 83160 98280 83160 98280 83160 83160 98280 98280 98280...

output:

528912947

result:

ok single line: '528912947'

Test #24:

score: 0
Accepted
time: 211ms
memory: 20700kb

input:

100000
98280 83160 98280 83160 98280 83160 83160 98280 83160 98280 98280 83160 83160 98280 98280 98280 83160 83160 98280 83160 83160 98280 98280 98280 83160 83160 83160 98280 98280 98280 83160 98280 83160 98280 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 98280 98280 98280 98280...

output:

663696018

result:

ok single line: '663696018'

Test #25:

score: 0
Accepted
time: 221ms
memory: 20752kb

input:

100000
98280 83160 83160 83160 83160 83160 83160 98280 83160 98280 83160 83160 98280 83160 83160 98280 83160 83160 98280 98280 83160 98280 83160 83160 83160 98280 83160 98280 98280 98280 98280 83160 98280 83160 98280 83160 98280 98280 98280 98280 98280 98280 98280 83160 83160 98280 98280 98280 83160...

output:

185293781

result:

ok single line: '185293781'

Test #26:

score: 0
Accepted
time: 214ms
memory: 20692kb

input:

100000
83160 98280 83160 98280 98280 83160 98280 98280 83160 98280 83160 98280 98280 83160 83160 98280 83160 83160 83160 98280 98280 98280 98280 98280 83160 98280 83160 83160 98280 83160 98280 98280 83160 83160 83160 83160 83160 83160 83160 83160 98280 98280 98280 98280 83160 83160 83160 83160 98280...

output:

265618970

result:

ok single line: '265618970'

Test #27:

score: 0
Accepted
time: 146ms
memory: 20640kb

input:

100000
6748 69788 47260 32480 33942 8188 11479 78664 53113 73255 72304 66716 84089 23818 89927 12933 30905 34034 84229 54762 91319 49293 94715 87966 91496 99505 17334 38844 78839 99605 3668 3081 4280 49023 55926 37506 53303 5751 17404 69716 65284 67418 34181 6252 63092 13391 50498 63161 2336 78092 6...

output:

160307784

result:

ok single line: '160307784'

Test #28:

score: 0
Accepted
time: 126ms
memory: 20720kb

input:

100000
36693 74588 16740 13832 50825 52864 16936 18083 3638 13862 70146 96614 58612 48809 99800 32563 34063 39829 25887 63951 99448 13271 85503 77170 83384 47076 3866 40138 83223 18369 69671 94601 97967 42839 56265 72834 37368 78674 57258 91559 41290 11977 57230 95197 10241 49035 2851 91122 24829 17...

output:

554262457

result:

ok single line: '554262457'

Test #29:

score: 0
Accepted
time: 155ms
memory: 20700kb

input:

100000
84569 34031 4228 7376 19559 52455 28768 29106 53141 13488 23960 29617 7830 62630 11135 33979 12467 48342 5864 40166 82966 47314 34488 2828 2527 18966 73049 36609 23768 89555 29171 93051 1991 49912 35098 68600 39096 78039 85825 11757 70024 14491 57941 53860 89313 63841 74508 40403 34047 42177 ...

output:

797657432

result:

ok single line: '797657432'

Test #30:

score: 0
Accepted
time: 144ms
memory: 20888kb

input:

100000
45286 93143 22827 37213 37159 18971 51524 32208 59869 28956 53278 88584 93369 89164 49622 51530 25244 64430 45694 75680 20664 23452 14824 18371 92132 33013 27654 79082 9740 50616 81017 70773 52583 80609 44874 55839 41913 79135 51204 2289 61357 44901 31020 48708 65048 63264 91120 82386 9556 54...

output:

76546307

result:

ok single line: '76546307'

Test #31:

score: 0
Accepted
time: 131ms
memory: 20708kb

input:

100000
18017 13136 53161 11222 34529 90802 19730 5468 34092 80846 4644 22895 8597 79211 29451 29153 70397 80427 41431 59258 8714 39102 26588 64092 6542 39933 10714 43534 36605 98350 36454 90632 61650 92387 13238 35631 98838 68804 62993 91499 25414 83427 8773 8041 84712 87832 92207 80279 32098 79683 ...

output:

909129079

result:

ok single line: '909129079'

Test #32:

score: 0
Accepted
time: 106ms
memory: 20312kb

input:

63
221 895 89 673 890 9 855 685 232 330 21 868 659 982 291 20 364 952 770 906 288 853 547 430 447 734 14 411 422 242 915 728 454 937 948 129 803 914 713 118 277 390 658 154 938 394 649 45 66 513 774 811 914 664 672 595 154 873 579 841 135 40 84

output:

63778565

result:

ok single line: '63778565'

Test #33:

score: 0
Accepted
time: 111ms
memory: 20316kb

input:

56
770 448 54 926 667 184 139 840 118 577 469 470 388 793 208 743 626 970 11 847 874 362 226 695 655 955 363 723 588 660 697 315 590 750 356 858 173 151 823 514 392 171 9 343 918 206 189 767 21 627 826 608 246 856 611 186

output:

876601404

result:

ok single line: '876601404'