arrow_forward
همه ارسالها
جزئیات ارسال کد#358
برای پسندیدن وارد شوید
1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 ios::sync_with_stdio(0);
7 cin.tie(0);
8
9 int n;
10 cin >> n;
11
12 vector<int> hash(100001, -1);
13 long long sum = 0;
14
15 for (int i = 0; i < 2 * n; ++i) {
16 int x;
17 cin >> x;
18
19 if (hash[x] == -1)
20 hash[x] = i;
21 else {
22 hash[x] = abs(i - hash[x]);
23 sum += hash[x];
24 }
25 }
26
27 cout << sum;
28}
کد ارسالشده برای داوری خودکار هاتکدز
UTF-8