Guest User

Untitled

a guest
Jan 23rd, 2016
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define fi first
  5. #define se second
  6. #define all(v) v.begin(), v.end()
  7.  
  8. using namespace std;
  9. using ll = uint64_t;
  10.  
  11. void solve() {
  12.   const ll MOD = 1000000000 + 7;
  13.   const ll BUBEN = MOD * MOD * 17;
  14.   int n;
  15.   cin >> n;
  16.   vector<pair<ll,ll>> snakes(n);
  17.   for (int i = 0; i < n; i++) {
  18.     cin >> snakes[i].first >> snakes[i].second;
  19.   }
  20.   sort(all(snakes));
  21.   ll res = 0;
  22.   for (int i = 0; i < n; i++) {
  23.     for (int j = i + 1; j < n; j++) {
  24.       if (snakes[j].second > snakes[i].second) break;
  25.       if (snakes[j].second == snakes[i].second) {
  26.         ll dx = snakes[j].first - snakes[i].first;
  27.         res += dx * dx;
  28.         if (res >= BUBEN)
  29.           res -= BUBEN;
  30.       }
  31.     }
  32.   }
  33.   res %= MOD;
  34.   cout << res << endl;
  35. }
  36.  
  37. int main() {
  38.   int tests;
  39.   cin >> tests;
  40.   for (int t = 1; t <= tests; t++) {
  41.     cout << "Case #" << t << ": ";
  42.     solve();
  43.   }
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment