fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void hhh() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. }
  8.  
  9. typedef long long ll;
  10.  
  11. int main() {
  12. hhh();
  13. int n ;
  14. cin >> n ;
  15. unordered_set <int > ms;
  16. for( int i = 0 ; i < n ; i ++) {
  17. int x ;
  18. cin >> x ;
  19. ms.insert( x );
  20. }
  21. int q ;
  22. cin >> q ;
  23. while( q-- ) {
  24. int val ;
  25. cin >> val ;
  26. bool fl = 0 ;
  27. int st = 1 ;
  28. for( auto it = ms.begin(); it != ms.end() ; it++) {
  29. if( *it == val ) {
  30. int idx = distance (ms.begin(), it ) +1 ;
  31. ms.erase(it); // neu dung erase val se xao het tat ca trong val
  32. cout << st <<"\n";
  33. fl = 1 ;
  34. break;
  35. }
  36. ++st;
  37. }
  38. if( ! fl) cout <<"-1\n";
  39.  
  40. }
  41.  
  42.  
  43. }
  44.  
Success #stdin #stdout 0s 5312KB
stdin
7
3 1 2 3 2 1 1
7
3
2
1
3
1
2
3

stdout
2
1
1
-1
-1
-1
-1