Guest User

Untitled

a guest
Jun 3rd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int A[50004], B[50004];
  5.  
  6. int main(){
  7.  
  8. int Q;
  9. scanf("%d", &Q);
  10.  
  11. while(Q--)
  12. {
  13. int N;
  14. scanf("%d", &N);
  15.  
  16. for(int i=1; i<=N; i++)
  17. scanf("%d", &A[i]);
  18.  
  19. sort(A+1, A+1+N);
  20. memset(B, 0, sizeof(B));
  21.  
  22. int v;
  23. scanf("%d", &v);
  24.  
  25. while(v--)
  26. {
  27. int L, R;
  28. scanf("%d %d", &L, &R);
  29.  
  30. L = lower_bound(A+1, A+1+N, L) - A;
  31. R = upper_bound(A+1, A+1+N, R) - A;
  32.  
  33. B[L]++, B[R]--;
  34. }
  35.  
  36. int ans = 0;
  37.  
  38. for(int i=1; i<=N; i++)
  39. {
  40. B[i] += B[i-1];
  41. ans += (B[i]>0);
  42. }
  43.  
  44. printf("%d\n", ans);
  45. }
  46.  
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment