QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138528#5455. TreeScriptammardab3an#WA 1ms3544kbC++17786b2023-08-11 21:30:082023-08-11 21:30:10

Judging History

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

  • [2023-08-11 21:30:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3544kb
  • [2023-08-11 21:30:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main(){

    int t;
    cin >> t;

    while(t--){

        int n;
        cin >> n;

        vector<pair<int, int>> v(n);

        for(int i = 0; i < n; i++){
            int prev;
            cin >> prev;
            prev--;
            if(prev != -1) v[prev].second = i-1;
            v[i] = {i, i};
        }

        vector<int> pre(n+3, 0);
        for(int i = 0; i < n; i++){
            auto [f, s] = v[i];
            pre[f]++;
            pre[s+1]--;
        }

        int ans = 0;
        for(int i = 0; i <= n; i++){
            if(i)
            pre[i] += pre[i-1];
            ans = max(ans, pre[i]);
        }

        cout << ans << endl;

    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3544kb

input:

2
3
0 1 2
7
0 1 2 2 1 4 1

output:

1
3

result:

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