fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define F first
  4. #define S second
  5. #define ll long long
  6. #define len length()
  7. #define sqr(x) x*x
  8. #define pb push_back
  9. #define mp make_pair
  10. #define sz(x) ((int) (x).size())
  11. #define all(x) x.begin(), x.end()
  12. #define allr(x) x.rbegin(), x.rend()
  13. #define bp(x) __builtin_popcount(x)
  14. #define INF numeric_limits<long long int>::max()
  15. #define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  16. #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  17. #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
  18.  
  19. const int maxn = (int)1e6;
  20. const int mod = (int)1e9 + 7;
  21.  
  22. using namespace std;
  23.  
  24. int n;
  25. int cnt;
  26. bool ok=false;
  27. vector<pair<int,int> > v;
  28.  
  29. main(){
  30. scanf("%d",&n);
  31. for(int i=0; i < n; i++){
  32. int x,y;
  33. scanf("%d%d",&x,&y);
  34. v.pb(mp(y,x));
  35. }
  36. sort(all(v));
  37. //puts("");
  38. for(int i=1; i < n; i++){
  39. if(v[i-1].F == v[i].F){
  40. ok=true;
  41. break;
  42. }
  43. }
  44. if(ok){
  45. for(int i=0; i < n; i++){
  46. swap(v[i].F,v[i].S);
  47. }
  48. sort(all(v));
  49. for(int i=1; i < n; i++){
  50. if(v[i-1].F < v[i].S)
  51. cnt++;
  52. }
  53. printf("%d",cnt);
  54. }
  55. else{
  56. for(int i=1; i < n; i++){
  57. if(v[i-1].F < v[i].S)
  58. cnt++;
  59. }
  60. printf("%d",cnt);
  61. }
  62.  
  63.  
  64.  
  65.  
  66. return 0;
  67. }
  68. //by ELDAN
  69.  
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
Standard output is empty