Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- const int sz = 300300;
- int n,m;
- int p[sz];
- set<int> Set[sz];
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin>>n>>m;
- for(int i=0;i<n;i++){
- cin>>p[i];
- p[i]--;
- }
- for(int i=0;i<m;i++){
- int f,t;
- cin>>f>>t;
- f--,t--;
- Set[f].insert(t);
- }
- set<int> curBadSet;
- int ans =0;
- for(int j=n-2;j>=0;j--){
- if(Set[p[j]].find(p[n-1]) == Set[p[j]].end()){
- curBadSet.insert(p[j]);
- } else{
- int active = 0;
- for(int i : Set[p[j]]){
- if(curBadSet.find(i) != curBadSet.end()){
- active++;
- }
- }
- if(active != curBadSet.size()){
- curBadSet.insert(p[j]);
- }
- }
- ans = n - j - 1 - curBadSet.size();
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement