QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138528 | #5455. TreeScript | ammardab3an# | WA | 1ms | 3544kb | C++17 | 786b | 2023-08-11 21:30:08 | 2023-08-11 21:30:10 |
Judging History
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'