-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (41 loc) · 1.01 KB
/
main.cpp
File metadata and controls
51 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<vector>
using namespace std;
int table[100000 + 10];
int r_table[100000 + 10];
int main() {
int n;
cin >> n;
vector<int> array(n + 10);
for(int i = 0 ; i < n ; i++) {
cin >> array[i];
}
int m;
cin >> m;
vector<int> queries(m + 10);
for(int i = 0; i < m ; i++) {
cin >> queries[i];
}
for(int i = 0; i < n + 8; i++) {
table[i] = -1;
r_table[i] = -1;
}
for(int i = 0; i < n ; i++) {
if(table[array[i]] == -1) {
table[array[i]] = i;
}
}
for(int i = n - 1; i >= 0; i--) {
if(r_table[array[i]] == -1) {
r_table[array[i]] = n - i - 1;
}
}
long long int vash = 0;
long long int sash = 0;
for(int i = 0 ; i < m ; i++ ) {
// cout << table[queries[i]] << " " << r_table[queries[i]] << endl;
vash = vash + table[queries[i]] + 1;
sash = sash + r_table[queries[i]] + 1;
}
cout << vash << " " << sash << endl;
}