Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int const N = 200000;
int fr[N + 1];
bool bad[N + 1];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	f(i, 1, n + 1){
		int h;
		scanf("%d", &h);
		++fr[h];
	}
	f(i, 0, m){
		int ind, h;
		scanf("%d%d", &ind, &h);
		bad[h] = true;
	}
	ll an = 0;
	int cb = n;
	f(i, 1, N + 1){
		if (!bad[i])an += cb;
		cb -= fr[i];
	}
	printf("%lld\n", an);
}
Copy
Dr. Evil Motarack
GNU G++14
41 ms
1.6 MB
Accepted