This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "september.h"
using namespace std;
#define ll long long
#define ar array
#define rep(i, n) for(int i = 0; i<(int)n; ++i)
const int mxN = 2e5+5, M = 1e9+7;
int ans[mxN];
vector<int> adj[mxN];
void init(int n){
rep(i, n){
ans[i] = 0;
adj[i].clear();
}
}
int solve(int N, int M, vector<int> F, vector<vector<int>> S){
init(N);
rep(i, N-1){
adj[F[i+1]].push_back(i+1);
}
for(vector<int> v : S){
vector<int> status(N);
int bad = 0;
int ff = 0;
v.push_back(0);
reverse(v.begin(), v.end());
vector<int> f(N);
rep(j, N){
f[v[j]] = 1;
if(v[j] > 0 && f[F[v[j]]] == 0) bad++;
for(auto ve : adj[v[j]]){
if(f[ve] == 1) bad--;
}
if(status[v[j]] != 0) ff--;
status[v[j]]++;
if(status[v[j]] != 0) ff++;
if(status[S[0][j]] != 0) ff--;
status[S[0][j]]--;
if(status[S[0][j]] != 0) ff++;
if(bad == 0 && ff == 0){
ans[j]++;
}
}
}
ll anss = -1;
rep(i, N){
anss += (ans[i] == M);
}
return anss;
}
// int main(){
// #ifdef _DEBUG
// // freopen("input.txt", "r", stdin);
// // freopen("output.txt", "w", stdout);
// #endif
// std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |