fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "icebear"
  33. /*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */
  34.  
  35. const int MOD = 1e9 + 7;
  36. const int inf = 1e9 + 27092008;
  37. const ll INF = 1e18 + 27092008;
  38. const int N = 5000 + 5;
  39. int numTree;
  40. struct Tree {
  41. int x, y;
  42. bool operator < (const Tree &other) const {
  43. if (x == other.x) return y < other.y;
  44. return x < other.x;
  45. }
  46. } tree[N];
  47.  
  48. void init(void) {
  49. cin >> numTree;
  50. FOR(i, 1, numTree) cin >> tree[i].x >> tree[i].y;
  51. sort(tree + 1, tree + numTree + 1);
  52. }
  53.  
  54. void process(void) {
  55. int ans = 0;
  56. FOR(i, 1, numTree) {
  57. set<int> Y;
  58. FOR(j, i + 1, numTree) {
  59. int l = tree[i].y;
  60. int r = tree[j].y;
  61. if (l > r) swap(l, r);
  62. auto it = Y.lower_bound(l);
  63. if (it != Y.end() && it != Y.begin() && *it > r) {
  64. auto prv = prev(it);
  65. ans += 1LL * (tree[j].x - tree[i].x - 1) * (*it - *prv - 1) % MOD;
  66. if (ans >= MOD) ans -= MOD;
  67. }
  68. Y.insert(tree[j].y);
  69. }
  70. }
  71. cout << ans;
  72. }
  73.  
  74. int main() {
  75. ios_base::sync_with_stdio(0);
  76. cin.tie(0); cout.tie(0);
  77. if (fopen(task".inp", "r")) {
  78. freopen(task".inp", "r", stdin);
  79. freopen(task".out", "w", stdout);
  80. }
  81. int tc = 1;
  82. // cin >> tc;
  83. while(tc--) {
  84. init();
  85. process();
  86. }
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty