QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104488#5098. 第一代图灵机bashkort0 459ms31564kbC++203.4kb2023-05-10 20:46:352023-05-10 20:46:36

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:46:36]
  • Judged
  • Verdict: 0
  • Time: 459ms
  • Memory: 31564kb
  • [2023-05-10 20:46:35]
  • 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);
        }
    }

    ll rangeQuery(int l, int r, int &mn, int x = 1, int lx = 0, int rx = sz) {
        if (l >= rx || lx >= r) {
            return 0;
        }
        if (l <= lx && rx <= r) {
            ll ans = vertexQuery(x, mn);
            mn = min(mn, t[x].mn);
            return ans;
        }
        int mid = lx + rx >> 1;
        return max(rangeQuery(l, r, mn, x << 1 | 1, mid, rx), rangeQuery(l, r, mn, x << 1, lx, mid));
    }

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

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) -> ll {
        ll ans = ST::rangeQuery(l, r, r);
        return max(ans, pref[r] - pref[l]);
    };

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

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

    return 0;
}


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 3856kb

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:

6757417
4223202
994925
3879879
3834758
826265
790549
3757812
6555680
6600573
4358060
3952946
4037660
5637206
295578
2024009
818244
304912
241567
3288554
6761965
4606934
6538070
39374
1676016
6316843
433061
3445255
3254756
1154055
1274718
2371908
7692013
7100673
6022517
3789692
9792831
2864895
734436...

result:

wrong answer 1st lines differ - expected: '118571', found: '6757417'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 459ms
memory: 28636kb

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:

14514423231
3009382401
3091862976
4121601459
10593138905
14836335064
14042420368
10453400460
2826482673
16088005116
156603089
691692746
13166698270
11615299096
15866435330
9621745410
4998174089
682411676
7603146296
13314589101
12595911600
5290205445
4767572878
3799018246
2601282213
3586277762
136893...

result:

wrong answer 1st lines differ - expected: '1232419', found: '14514423231'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 324ms
memory: 31564kb

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:

6621675747
13369003497
931196267
2620341979
749682138
9533329416
3004747940
9839424653
13388927858
2836487010
122809831
546615127
3318928812
13401800941
12305820842
3915278550
4220161165
4196276921
17911243132
4642609744
12142861673
5386102380
3380303636
1694632357
11944237923
2557674030
14743060736...

result:

wrong answer 1st lines differ - expected: '46702944', found: '6621675747'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%