Source Code
#include <bits/stdc++.h>
using namespace std;
    
int main (){

  #ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1","r",stdin);
  #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  int N = 2e5 + 5;
  int pref[N] = {};
  bool no[N] = {};
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ++pref[1];
    --pref[x + 1];
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    no[y] = 1;
  }
  long long ans = 0;
  for (int i = 1; i < N; ++i) {
    pref[i] += pref[i - 1];
    if (!no[i]) {
      ans += pref[i];
    }
  }
  cout << ans;

  return 0;
}
Copy
Dr. Evil SuhaibSawalha1
GNU G++17
37 ms
1.8 MB
Accepted