Source Code
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define TEST int t;cin>>t;while(t--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fr first
#define sc second
#define popcount __builtin_popcountll
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const ll mod=1000000007;
typedef vector<int,int> p1;
typedef vector<ll,ll> p2;
int h[2*100010],a,b;
int main()
{
    IOS;
    //TEST{

  int n,m;
  cin>>n>>m;

  map<int,int>mm,mk;
    for(int i=1;i<=n;i++){cin>>h[i]; mk[h[i]]++;}
    sort(h+1,h+1+n);
    rep(i,m){
        cin>>a>>b;
        mm[b]=1;
    }
ll ans=0;
    int j=0;
    for(int i=h[n];i>0;i--){
             j+=mk[i];
    if(mm[i])continue;

        ans+=j;
    }
 cout<<ans;
cout<<endl;
//}
    return 0;
}
Copy
Dr. Evil AlCoach
GNU G++17
202 ms
20.4 MB
Accepted