Advertisement
999ms

Untitled

Mar 11th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef long double ld;
  5.  
  6. const int sz = 300300;
  7. int n,m;
  8. int p[sz];
  9. set<int> Set[sz];
  10.  
  11. int main(){
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(nullptr);
  14.  
  15.     cin>>n>>m;
  16.     for(int i=0;i<n;i++){
  17.         cin>>p[i];
  18.         p[i]--;
  19.     }
  20.  
  21.     for(int i=0;i<m;i++){
  22.         int f,t;
  23.         cin>>f>>t;
  24.         f--,t--;
  25.         Set[f].insert(t);
  26.     }
  27.     set<int> curBadSet;
  28.     int ans  =0;
  29.     for(int j=n-2;j>=0;j--){
  30.         if(Set[p[j]].find(p[n-1]) == Set[p[j]].end()){
  31.             curBadSet.insert(p[j]);
  32.         }   else{
  33.             int active = 0;
  34.             for(int i : Set[p[j]]){
  35.                 if(curBadSet.find(i) != curBadSet.end()){
  36.                     active++;
  37.                 }
  38.             }
  39.             if(active != curBadSet.size()){
  40.                 curBadSet.insert(p[j]);
  41.             }
  42.         }
  43.         ans = n - j - 1 - curBadSet.size();
  44.     }
  45.     cout<<ans<<endl;
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement