#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,tune=native")
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 300005
int n;
array<int, 2> a[N]; ll z;
unordered_map<int, int> b;
int main()
{
ShinLena;
for (int i = (cin >> n, 0); i < n; ++i) cin >> a[i][0] >> a[i][1], ++b[a[i][1]];
sort(a, a+n); n = unique(a, a+n) - a;
ll d=0;
for (int f, e = 0, i = 0, l = -1; i < n; ++i)
{
f = a[i][0] == l;
l += (a[i][0] - l) * !f, d *= f, e *= f;
z += d + (b[a[i][1]] - 1ll) * e;
++e, d += b[a[i][1]] - 1;
}
cout << z;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
4 ms |
788 KB |
Output is correct |
15 |
Correct |
37 ms |
3840 KB |
Output is correct |
16 |
Correct |
36 ms |
3984 KB |
Output is correct |
17 |
Correct |
42 ms |
3764 KB |
Output is correct |
18 |
Correct |
34 ms |
3876 KB |
Output is correct |
19 |
Correct |
90 ms |
4024 KB |
Output is correct |
20 |
Correct |
65 ms |
4016 KB |
Output is correct |
21 |
Correct |
97 ms |
4088 KB |
Output is correct |
22 |
Correct |
98 ms |
4024 KB |
Output is correct |