QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104483#5098. 第一代图灵机bashkort100 ✓701ms43172kbC++203.9kb2023-05-10 20:38:182023-05-10 20:38:22

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-10 20:38:22]
  • Judged
  • Verdict: 100
  • Time: 701ms
  • Memory: 43172kb
  • [2023-05-10 20:38:18]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int N = 2e5 + 228;

ll pref[N];
int n;

namespace ST {
    struct Info {
        ll ans = 0;
        int mn = 0;
    };

    vector<Info> t;
    vector<ll> ansL;
    int sz = 1;

    ll vertexQuery(int x, int mn) {
        if (x >= sz) {
            if (x - sz >= n) {
                return 0;
            }
            return t[x].mn >= mn ? 0 : pref[mn] - pref[x - sz + 1];
        }

        if (t[x << 1 | 1].mn < mn) {
            return max(ansL[x], vertexQuery(x << 1 | 1, mn));
        } else {
            return vertexQuery(x << 1, mn);
        }
    }

    void pull(int x) {
        t[x].mn = min(t[x << 1].mn, t[x << 1 | 1].mn);
        ansL[x] = vertexQuery(x << 1, t[x << 1 | 1].mn);
        t[x].ans = max(ansL[x], t[x << 1 | 1].ans);
    }

    void init(int n, vector<int> nxt) {
        sz = 1 << __lg(n) + !!(n & (n - 1));
        t.assign(sz << 1, Info());
        ansL.assign(sz << 1, 0);

        for (int i = 0; i < n; ++i) {
            t[i + sz].mn = nxt[i];
            t[i + sz].ans = 0;
        }
        for (int i = sz - 1; i > 0; --i) {
            pull(i);
        }
    }

    vector<int> stk;

    void rangeQuery(int l, int r, int x, int lx = 0, int rx = sz) {
        if (l >= rx || lx >= r) {
            return;
        }
        if (l <= lx && rx <= r) {
            return stk.push_back(x);
        }
        int mid = lx + rx >> 1;
        rangeQuery(l, r, x << 1, lx, mid), rangeQuery(l, r, x << 1 | 1, mid, rx);
    }

    void modify(int x, int i) {
        t[x + sz].mn = i;
        t[x + sz].ans = 0;
        for (x += sz; x >>= 1;) {
            pull(x);
        }
    }

    vector<int> rangeQuery(int l, int r) {
        stk.clear();
        rangeQuery(l, r, 1, 0, sz);
        return stk;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int m, q;
    cin >> n >> m >> q;

    for (int i = 1; i <= n; ++i) {
        cin >> pref[i];
        pref[i] += pref[i - 1];
    }

    vector<int> c(n), nxt(n, n), last(m, -1);
    vector<set<int>> st(m);

    for (int i = 0; i < m; ++i) {
        st[i].insert(-1);
        st[i].insert(n);
    }

    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        c[i] -= 1;
        st[c[i]].insert(i);

        if (last[c[i]] != -1) {
            nxt[last[c[i]]] = i;
        }
        last[c[i]] = i;
    }

    ST::init(n, nxt);

    auto modify = [&](int x, int to) {
        nxt[x] = to;
        ST::modify(x, to);
    };

    auto replace = [&](int x, int col) {
        if (c[x] == col) {
            return;
        }

        st[c[x]].erase(x);
        st[col].insert(x);

        int p = *prev(st[c[x]].lower_bound(x));
        int np = *prev(st[col].lower_bound(x));
        int nx = *st[col].upper_bound(x);
        int npx = *st[c[x]].upper_bound(p);

        if (p != -1) {
            modify(p, npx);
        }
        if (np != -1) {
            modify(np, x);
        }
        modify(x, nx);

        c[x] = col;
    };

    auto query = [&](int l, int r) { // [l, r)
        vector<int> stk = ST::rangeQuery(l, r);
        int mn = r;
        ll ans = ST::vertexQuery(stk.back(), r);

        for (int k = stk.size() - 1; k >= 0; --k) {
            mn = min(mn, ST::t[stk[k]].mn);
            if (k > 0) {
                ans = max(ans, ST::vertexQuery(stk[k - 1], mn));
            }
        }

        if (mn >= l) {
            ans = max(ans, pref[mn] - pref[l]);
        }

        return ans;
    };

    while (q--) {
        int tp, a, b;
        cin >> tp >> a >> b;
        a -= 1, b -= 1;

        if (tp == 1) {
            cout << query(a, b + 1) << '\n';
        } else {
            replace(a, b);
        }
    }

    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 5ms
memory: 3872kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

118571
90725
79596
95154
95154
94493
72411
100567
100567
100567
100567
90725
100567
100567
90725
118571
94493
95154
58191
118571
100567
100567
100567
39374
89208
118571
99923
100567
100567
95724
87252
100567
118571
100567
100567
100567
100567
100567
100567
26617
100567
99923
100567
118571
100567
100...

result:

ok 3799 lines

Test #2:

score: 0
Accepted
time: 9ms
memory: 4104kb

input:

5000 1000 5000
451 521 3465 4281 3422 1186 2547 3341 2060 1467 717 2115 2513 2471 1399 1812 3070 2173 521 1621 2801 4020 4493 138 4162 97 1179 171 4011 3340 2393 689 1830 3981 2352 3352 3561 2969 1037 1205 2390 3916 1578 2313 2433 885 1097 1820 739 4483 3241 3861 1547 665 1449 4133 4877 1005 3510 18...

output:

188595
209663
209663
209663
209663
209663
209282
209663
209663
176195
156041
141623
176195
209663
209663
209282
175706
209663
209663
209663
209663
209663
209282
209663
209663
209663
188595
209282
209663
183686
209663
163197
209663
183686
209663
183686
209663
175706
209663
209663
209663
209663
209663...

result:

ok 3724 lines

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 538ms
memory: 28492kb

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:

1232419
1222519
1232419
1232419
1232419
1232419
1232419
1232419
1232419
1232419
1040511
1148070
1232419
1232419
1232419
1232419
1206368
1206368
1232419
1232419
1232419
1222519
1167757
1206368
1214212
1222519
1232419
1222519
1222519
1160928
1011843
1232419
1232419
1189403
1222519
1232419
1222519
1148...

result:

ok 150001 lines

Test #4:

score: 0
Accepted
time: 523ms
memory: 28492kb

input:

200000 10 200000
30667 76440 31754 172209 119166 184237 184837 164501 15853 166011 36513 137215 94697 78289 80876 166026 32881 92643 80793 147949 182785 165617 115046 182305 83873 100693 190096 140639 74339 167389 43600 107001 37622 20476 13072 47637 49833 39017 93821 44733 195599 196124 58413 19221...

output:

1373616
1224613
1269269
1105924
1211028
1128748
1373616
1285605
1373616
1373616
1317624
1317624
1373616
1317624
1187052
1373616
1373616
1317624
1317624
1187052
1126035
1317624
1131579
1269269
1317624
1169493
1317624
1317624
1285605
1373616
1069964
1373616
1373616
1373616
1373616
1317624
1373616
1373...

result:

ok 150029 lines

Subtask #3:

score: 20
Accepted

Test #5:

score: 20
Accepted
time: 452ms
memory: 31688kb

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:

46702944
46702944
38383720
38615532
38615532
42801975
39035571
46702944
46702944
46702944
27438528
38402892
46702944
46702944
42801975
42323113
39035571
42323113
46702944
46702944
46702944
41821993
46702944
34075405
46702944
38615532
46702944
28680653
46702944
42801975
42801975
38025842
46702944
467...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 434ms
memory: 31488kb

input:

200000 20000 200000
35105 74665 63960 162062 164953 63344 145369 115837 108866 61866 110690 123641 106889 65531 115933 163273 7531 128251 158561 169221 149787 40911 54465 92737 73473 10609 62701 89599 40007 40272 7318 129047 171198 90131 111281 85645 174001 140289 135851 26785 136485 31989 16313 888...

output:

43816163
35764822
45394839
45394839
45394839
43816163
45394839
43816163
40900280
38802753
45394839
45394839
43816163
34715395
45394839
43816163
43816163
45394839
43816163
45394839
45394839
43816163
35764822
45394839
43816163
43816163
16638306
45394839
35764822
45394839
34921501
45394839
45394839
409...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 458ms
memory: 31480kb

input:

200000 20000 200000
80203 178041 44172 21001 54489 120807 60663 147301 166763 49071 98913 115641 30627 164382 54165 165057 46105 9628 57953 86346 8273 137848 44871 119728 107309 132201 72483 198451 58505 185062 27039 49401 172444 101505 180973 59256 44859 53105 195233 161425 132423 2566 189331 15869...

output:

44318499
33827474
43556508
44318499
43556508
38914187
44318499
43556508
47858466
44318499
40709211
43556508
35706654
43556508
44318499
44318499
47858466
44318499
35359541
43556508
43556508
43556508
47858466
31755901
43556508
44318499
43556508
43556508
44318499
44318499
44318499
44318499
43556508
443...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 430ms
memory: 31560kb

input:

200000 20000 200000
69757 155771 81753 9285 168151 179881 122502 198324 140481 33185 155861 173423 117211 80727 63754 167913 121921 185921 182266 24801 167005 191511 77176 176741 117041 42534 10209 6241 83970 67652 164225 155249 125057 23841 71911 133150 79732 125061 7111 29841 142343 129299 155501 ...

output:

54623112
54623112
54623112
36983972
41889300
49604086
43664569
54623112
42438674
39404039
43664569
35418806
43664569
54623112
49604086
49604086
42438674
54623112
54623112
33869050
54623112
42438674
36847615
39404039
54623112
54623112
43664569
49604086
42438674
54623112
54623112
43664569
49604086
424...

result:

ok 200000 lines

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #9:

score: 20
Accepted
time: 110ms
memory: 9564kb

input:

50000 1000 50000
22098 40691 15626 6766 15467 15377 43375 7991 25841 6053 2031 38833 19761 42385 9421 28399 42001 15985 31206 30047 14001 7441 8377 5217 4402 37695 41393 25926 38137 32913 23203 31265 31401 32772 32905 24167 5233 24058 41685 26999 41 18461 15721 49365 49676 3151 29237 22894 37323 272...

output:

2734990
2469610
2734990
2734990
2734990
1967019
2734990
2469610
2469610
2388133
1799671
2469610
2734990
2734990
2734990
1957691
2273183
1952934
2734990
2168141
2273183
2436566
2734990
2469610
2469610
2273183
1986640
2734990
2152587
2152587
2436566
1957691
2734990
1952934
2469610
1927323
2734990
2734...

result:

ok 37426 lines

Test #10:

score: 0
Accepted
time: 101ms
memory: 9920kb

input:

50000 3000 50000
26345 22237 37825 18017 10571 36611 13641 34871 23281 33887 40852 37033 41999 7157 733 14250 26317 9438 4580 4336 15601 29921 20225 2668 14241 17493 20241 46199 1 12641 21281 45365 16691 27521 2163 11473 22971 2119 29681 21301 37841 34390 27153 27251 31049 25913 15678 36231 35301 22...

output:

2745361
3808608
3808608
4264616
4235767
4264616
3174029
4264616
3808608
4264616
3547291
4264616
3808608
3753676
4264616
4264616
3808608
4235767
3753676
4264616
3808608
4264616
3808608
3753676
3753676
4235767
4264616
4264616
3808608
4264616
4264616
2858660
4264616
4264616
3753676
4264616
4264616
3808...

result:

ok 37630 lines

Test #11:

score: 0
Accepted
time: 113ms
memory: 10128kb

input:

50000 5000 50000
31653 19639 4311 25169 31659 42766 11977 27731 23651 14701 8483 16344 2247 40647 9039 16489 35801 4082 38419 45856 17665 38754 43083 40671 32408 48467 27185 3144 31701 33733 6716 14133 2105 40551 3921 38809 24595 4295 30349 25016 16450 20081 39305 27803 15270 11705 17361 19567 29924...

output:

5126664
5142382
5142382
5142382
5142382
5142382
5142382
5142382
5142382
5126664
5410245
4278120
5142382
4278120
5772763
5410245
5126664
5410245
4745095
4525361
4525361
5410245
5410245
4525361
4420696
5410245
5142382
4745095
5772763
5410245
4238451
5410245
5410245
5410245
5410245
5410245
5410245
4745...

result:

ok 37522 lines

Test #12:

score: 0
Accepted
time: 74ms
memory: 13028kb

input:

50000 25000 50000
34538 6631 20121 905 26818 44368 30670 37731 40463 15201 39981 24285 41901 47121 5301 44467 49610 40975 31931 23680 2231 41395 15878 24760 30222 49987 22961 6951 33701 23633 9095 13546 7964 16011 38636 14817 13011 37269 27797 11376 7936 31649 40488 37836 11065 7891 39391 21437 4694...

output:

266141794
618840980
145032186
57978911
409865397
29353526
24595926
275518913
613677417
455611683
624185824
384230855
137601929
58120402
80585932
246836251
626286654
161877183
385544628
401507685
86584674
54668579
626286654
379213776
343390891
455517388
324928870
566756301
622591682
117295749
3414503...

result:

ok 25000 lines

Subtask #5:

score: 40
Accepted

Dependency #4:

100%
Accepted

Test #13:

score: 40
Accepted
time: 677ms
memory: 28624kb

input:

200000 1000 200000
86881 181241 36705 81141 134314 91161 170817 78506 98711 53236 135870 199649 121729 158986 42323 190297 144513 19767 104041 191515 30393 161425 177941 126191 43710 96703 113443 180950 172245 27687 83019 80185 56193 99571 141101 110667 133377 168529 16422 65729 99846 187702 68903 6...

output:

10804871
9487518
10804871
10131495
9660709
10804871
8068386
10804871
10035332
10804871
10804871
9899946
10131495
10804871
9949420
10804871
10131495
10804871
7958917
10744302
10804871
9807973
8135865
8611961
9660709
10804871
10804871
10804871
10804871
10804871
10804871
10804871
10035332
9267745
10804...

result:

ok 150020 lines

Test #14:

score: 0
Accepted
time: 669ms
memory: 29124kb

input:

200000 3000 200000
69585 192956 174831 72335 152803 136686 67101 108497 179011 69926 117235 91561 136325 130338 135185 2385 115275 62944 174541 182513 123591 36036 89805 80435 93907 30192 19477 73553 197625 701 145725 143697 126621 155508 141620 138065 195701 132047 181594 67795 29057 101451 169999 ...

output:

17233883
17233883
17233883
17995010
12489985
15404031
17233883
13308416
12905400
17995010
15204342
17233883
17233883
15204342
13359068
17233883
17233883
17995010
17233883
14945139
17233883
15849231
15849231
17233883
11327013
14161245
14699396
15404031
15404031
17995010
14699396
14059970
17233883
146...

result:

ok 150038 lines

Test #15:

score: 0
Accepted
time: 701ms
memory: 29372kb

input:

200000 5000 200000
17201 127195 92869 92115 163877 150099 137501 125281 73848 154356 114629 130911 28785 115201 4791 171606 131261 68833 59659 173160 181017 43120 199999 88945 181077 135801 109874 146955 11401 81225 175201 19979 187906 131153 25394 178998 159719 110956 73699 151351 167161 124516 182...

output:

21430621
23079602
24563877
22194197
20514929
23836619
23836619
24563877
24563877
24563877
23079602
23079602
24563877
21063983
23079602
24563877
17902460
23836619
18923858
21430621
24563877
23079602
24563877
24563877
23079602
23079602
23079602
24563877
23079602
24563877
20476150
23079602
18279658
214...

result:

ok 149973 lines

Test #16:

score: 0
Accepted
time: 623ms
memory: 29692kb

input:

200000 7000 200000
158795 153233 174457 184637 74035 57481 143377 103097 53931 138577 129297 29945 58329 146065 22261 87336 169237 195873 58619 31925 95594 94266 58565 160229 184711 80126 77803 167205 67326 94523 92699 109821 59841 114804 156004 147179 36393 197941 93476 175223 158069 146049 50915 8...

output:

22126921
23292954
27122215
22422162
25730255
27212893
27212893
27212893
27212893
27212893
27212893
27122215
26712308
25730255
23292954
27212893
25187231
27212893
23898005
27212893
27212893
23292954
21102462
27212893
27212893
27212893
27212893
20789318
17866647
19542340
23898005
27212893
23292954
272...

result:

ok 149938 lines

Test #17:

score: 0
Accepted
time: 631ms
memory: 29904kb

input:

200000 10000 200000
120424 61769 125409 150411 10089 107441 36535 71277 133581 68201 67351 37949 23145 167760 147601 151835 116358 172620 163809 1559 118437 111293 47805 69280 172592 67121 47195 122705 119416 136673 31859 14017 34801 174285 96841 157409 71043 22537 45621 180956 30671 23595 126305 14...

output:

30398066
29029811
30398066
26122006
28179045
30398066
24615590
28179045
28843553
28179045
29552087
30398066
29029811
30398066
29029811
27821911
26823161
30398066
30398066
30398066
29029811
30398066
29552087
30398066
30398066
30398066
27267673
29029811
30398066
28179045
29029811
30398066
30398066
303...

result:

ok 149978 lines

Test #18:

score: 0
Accepted
time: 643ms
memory: 33140kb

input:

200000 30000 200000
70076 50281 179262 22559 163438 45146 171725 26561 106303 79793 95951 107941 118587 46981 124225 87384 84151 41301 24025 75179 50480 192871 51836 11123 92881 149611 161 72753 41741 156046 26883 96862 2841 102781 167241 60466 177733 103265 63231 131126 78477 169431 17430 91243 192...

output:

43105784
43105784
33035231
43105784
42493563
43105784
18833565
43105784
54793879
43105784
40140521
42106064
42490681
54793879
54793879
29860020
40140521
42493563
42490681
54793879
54793879
54793879
43105784
54793879
54793879
42330331
54793879
54793879
43105784
42330331
43105784
43105784
54793879
424...

result:

ok 149960 lines

Test #19:

score: 0
Accepted
time: 603ms
memory: 35696kb

input:

200000 50000 200000
148904 96305 3344 148205 127406 87307 148499 22172 50849 108501 147368 45165 179501 150641 100537 177911 165923 8662 19450 48798 23813 183497 97728 38901 59797 105361 64077 21071 161291 19466 34225 196777 162401 60327 167103 52909 171363 52464 188759 30589 156949 3587 177262 7208...

output:

54768031
63161635
63161635
61577332
62811812
61577332
67939276
67939276
47442051
63161635
63161635
62811812
63161635
62811812
65064326
63161635
63161635
62811812
63161635
43557662
63161635
61577332
67939276
63161635
63161635
65064326
63161635
63161635
67939276
46376626
67939276
54768526
52049943
538...

result:

ok 149974 lines

Test #20:

score: 0
Accepted
time: 368ms
memory: 43172kb

input:

200000 100000 200000
193841 63820 113065 82561 4543 107415 183890 156991 188957 12071 29341 105161 144875 174401 164386 70571 131921 199361 34217 34657 7981 8881 90221 55153 148485 17691 43377 47251 19841 90941 49221 73989 194284 40625 196003 34363 179619 47089 51311 166113 108705 159536 46913 13412...

output:

9999389173
69350584
1867256955
6601041465
4628760925
7249873934
9276454879
231751091
4198473674
9341845134
3695393821
7924778865
5267185762
1261020341
6283563144
9979083864
9982115577
8629364468
9999006608
1240997394
9999389173
9548471657
5486096294
7008125553
9982711797
9591460160
4463729503
861391...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed