比赛 平凡的题目 评测结果 WAWWWWWWWA
题目名称 平凡的题面 最终得分 20
用户昵称 Binary10 运行时间 0.280 s
代码语言 C++ 内存使用 2.32 MiB
提交时间 2015-11-03 10:30:29
显示代码纯文本
  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int maxn = 1e5 + 10;
  5. struct Event{
  6. int x, type;
  7. bool operator < (const Event& rhs) const{
  8. if(x == rhs.x) return type < rhs.type;
  9. return x < rhs.x;
  10. }
  11. }a[maxn * 3];
  12. int n, m;
  13. int main()
  14. {
  15. freopen("bg.in", "r", stdin);
  16. freopen("bg.out", "w", stdout);
  17. scanf("%d%d", &n, &m);
  18. int l, r, e = n;
  19. for(int i = 0; i < n; i++){
  20. scanf("%d", &l);
  21. a[i] = (Event){l, 0};
  22. }
  23. for(int i = 0; i < m; i++){
  24. scanf("%d%d", &l, &r);
  25. a[e++] = (Event){l, -1};
  26. a[e++] = (Event){r, 1};
  27. }
  28. sort(a, a + e);
  29. int cnt = 0, ans = 0; l = 0;
  30. for(int i = 0; i < e; i++){
  31. if(a[i].type < 0) cnt = ++l;
  32. else if(a[i].type > 0) cnt = --l;
  33. else if(cnt > 0) {ans++; cnt--;}
  34. }
  35. printf("%d\n", ans);
  36. return 0;
  37. }