QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#668481#7678. The GamexDarkbluexWA 0ms3516kbC++171.4kb2024-10-23 14:36:042024-10-23 14:36:07

Judging History

This is the latest submission verdict.

  • [2024-10-23 14:36:07]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3516kb
  • [2024-10-23 14:36:04]
  • Submitted

answer

#include <bits/stdc++.h>

struct Fenwick {
    std::vector<int> t;
    int n;
    Fenwick(int _n) : n(_n), t(_n + 1, 0) {};

    void add(int x, int y) {
        for (; x <= n; x += x & -x) t[x] += y;
    }

    int query(int x) {
        int ans = 0;
        for (; x; x -= x & -x) ans += t[x];
        return ans;
    }
};

void solve() {
    int n, m;
    std::cin >> n >> m;
    
    std::vector<int> a(n + 1, 0);
    std::vector<char> vis(m + 1, 0);
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        vis[a[i]] = 1;
    }

    std::vector<int> pre(n + 1, 0);
    std::vector<int> last(m + 1, 0);
    for (int i = 1; i <= n; i++) {
        pre[i] = last[a[i]];
        last[a[i]] = i;
    }

    Fenwick x(n);
    int ans = -1;
    for (int i = 1; i <= n; i++) {
        ans = std::max(ans, x.query(i - 1) - x.query(pre[i]) - a[i]);
        if (pre[i]) x.add(pre[i], -1);
        x.add(i, 1);
    }

    for (int i = 1; i <= n; i++) {
        int mex = a[i];
        ans = std::max(ans, x.query(n) - x.query(last[a[i]]) - a[i]);
    }

    for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        ans = std::max(ans, x.query(n) - i);
        break;
    }
    std::cout << ans << '\n';
}

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

    int T;
    std::cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:

1
0
0
1
-1
-1

result:

wrong answer Wrong answer, number of operation is not correct (test case 1)