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>
using namespace std;
typedef long long ll;
#define vll vector<ll>
#define MAX 500005
vll v[MAX];
ll a[MAX];
ll mn[MAX],mx[MAX];
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
for(int i=0;i<N;i++){
v[i]={};a[i]=i;
}
for(int i=1;i<=N;i++){
v[F[i]].push_back(i);
}
for(int j=0;j<M;j++){
map<ll,ll> mp;
for(int i=0;i<N-1;i++){
mp[S[j][i]]=i;
mn[S[j][i]]=min(mn[S[j][i]],(ll)i);
mx[S[j][i]]=max(mx[S[j][i]],(ll)i);
}
for(int i=0;i<N-1;i++){
for(auto u : v[S[j][i]]){
a[i]=max(a[i],mp[u]);
}
}
}
for(int i=1;i<N-1;i++){
a[mn[i]]=max(mx[i],a[mn[i]]);
}
ll K=0;ll limit=0;
for(int i=0;i<N-1;i++){
//cout<<a[i]<<
limit=max(limit,a[i]);
if(limit==i)K++;
}
return K;
}
# | 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... |