Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define fi first
- #define se second
- #define all(v) v.begin(), v.end()
- using namespace std;
- using ll = uint64_t;
- void solve() {
- const ll MOD = 1000000000 + 7;
- const ll BUBEN = MOD * MOD * 17;
- int n;
- cin >> n;
- vector<pair<ll,ll>> snakes(n);
- for (int i = 0; i < n; i++) {
- cin >> snakes[i].first >> snakes[i].second;
- }
- sort(all(snakes));
- ll res = 0;
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- if (snakes[j].second > snakes[i].second) break;
- if (snakes[j].second == snakes[i].second) {
- ll dx = snakes[j].first - snakes[i].first;
- res += dx * dx;
- if (res >= BUBEN)
- res -= BUBEN;
- }
- }
- }
- res %= MOD;
- cout << res << endl;
- }
- int main() {
- int tests;
- cin >> tests;
- for (int t = 1; t <= tests; t++) {
- cout << "Case #" << t << ": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment