forked from Code-Cube-NITP/Competitive-Programming
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackOfPresents.cpp
More file actions
Latest commit
executable file
·42 lines (37 loc) · 968 Bytes
/
Copy pathStackOfPresents.cpp
File metadata and controls
executable file
·42 lines (37 loc) · 968 Bytes
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
// g++ StackOfPresents.cpp -o StackOfPresents && ./StackOfPresents
/*
*/
#include<bits/stdc++.h>
usingnamespacestd;
#definedeb(x) cout << #x << "" << x << endl
#definedeb2(x, y) cout << #x << "" << x << "" << #y << "" << y << endl
intmain(){
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
vector<int> table(n+1);
for(int i = 1; i <= n; i++){
int temp;
cin >> temp;
table[temp] = i;
}
intCI = 1;
int ans = 0;
for(int i = 0; i < m; i++){
int temp;
cin >> temp;
int psn = table[temp];
// deb2(psn, CI);
if(psn < CI) ans++;
else{
int k = (psn-CI-i)*2;
if (k < 0) k = 0;
ans = ans + k + 1;
CI = psn;
}
}
cout << ans << endl;
}
}