arrow_forward همه ارسال‌ها

جزئیات ارسال کد#242

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: C++
schedule
ارسال‌کننده و زمان:
Aram Maroofi (۳ سال پیش)
descriptionsolution.cpp ۳۴ خط • ۵۷۹ بایت
1#include <iostream>
2
3using namespace std;
4
5int main()
6{
7
8 int n;
9 cin >> n;
10 int a[2 * n];
11 int chortke[2 * n];
12 for ( int i = 0; i < (2 * n); i++ )
13 {
14 cin >> a[i];
15 chortke[ a[i] ] = -1;
16 }
17 int index = -2;
18 long long int x = 0;
19 for ( int i = 0; i < 2 * n; i++ )
20 {
21 if ( chortke[ a[i] ] == -1 )
22 {
23 index = i;
24 chortke[ a[i] ] = index;
25 }
26 else
27 {
28 x += (i - chortke[ a[i] ]);
29 }
30 }
31 cout << x;
32
33 return 0;
34}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8