QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#267228#7685. Barkley IIDAleksaWA 0ms30248kbC++141.5kb2023-11-27 02:29:272023-11-27 02:29:27

Judging History

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

  • [2023-11-27 02:29:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:30248kb
  • [2023-11-27 02:29:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

struct query {
    int l;
    int r;
    int mex;
};

const int N = 5e5 + 10;
int n, m;
int a[N];
vector<int> pos[N];
vector<query> qs;
vector<pair<int, int>> q[N];
int lst[N];

int fenw[N];

void update(int x, int val) { for(int i = x; i <= n; i += (i & -i)) fenw[i] += val; }
int get(int r) {
    int ans = 0;
    for(int i = r; i >= 1; i -= (i & -i)) ans += fenw[i];
    return ans;
}
int get(int l, int r) { return get(r) - get(l - 1); }

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pos[a[i]].push_back(i);
    }
    for(int mex = 1; mex <= n + 1; mex++) {
        vector<int> ind;
        ind.push_back(0);
        for(int i : pos[mex]) ind.push_back(i);
        ind.push_back(n + 1);
        for(int i = 1; i < ind.size(); i++) qs.push_back({ind[i - 1] + 1, ind[i] - 1, mex});
    }
    for(query Q : qs) q[Q.r].push_back({Q.l, Q.mex});
    int ans = 0;
    for(int i = 0; i <= n; i++) fenw[i] = 0;
    for(int i = 1; i <= n; i++) {
        if(lst[a[i]] > 0) update(lst[a[i]], -1);
        lst[a[i]] = i;
        update(lst[a[i]], 1);
        for(pair<int, int> p : q[i]) {
            int l = p.first, mex = p.second;
            ans = max(ans, get(l, i) - mex);
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    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: 30248kb

input:

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

output:

2
0

result:

wrong answer 2nd numbers differ - expected: '3', found: '0'