arrow_forward
همه ارسالها
جزئیات ارسال کد#181
برای پسندیدن وارد شوید
1#include <iostream>
2#include <string.h>
3
4using namespace std;
5
6int main()
7{
8 int n;
9 cin >> n;
10
11 int arr[n + 1];
12 memset(arr, -1, (n + 1) * sizeof(int));
13
14 int ans = 0;
15
16 for (int i = 0; i < 2 * n; i++)
17 {
18 int x;
19 cin >> x;
20 if (arr[x] == -1)
21 arr[x] = i;
22 else
23 ans += i - arr[x];
24 }
25
26 cout << ans;
27
28 return 0;
29}
کد ارسالشده برای داوری خودکار هاتکدز
UTF-8