fork(1) download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<map>
  4. #include<cstring>
  5.  
  6. using namespace std;
  7.  
  8. #define mx 30021
  9.  
  10. map< string, int > mp;
  11. int a[mx];
  12.  
  13. void update(int idx ){
  14.  
  15. while(idx < mx){
  16.  
  17. a[idx]++;
  18.  
  19. idx += (idx & -idx);
  20.  
  21. }
  22.  
  23. }
  24.  
  25. int count(int idx){
  26.  
  27.  
  28. int sum = 0;
  29.  
  30. while(idx > 0){
  31.  
  32. sum += a[idx];
  33.  
  34. idx -= (idx & -idx);
  35.  
  36. }
  37. return sum;
  38.  
  39. }
  40.  
  41.  
  42. int main(){
  43.  
  44. int n,t;
  45. scanf("%d",&t);
  46. char word[31];
  47. string s1;
  48. while(t--){
  49.  
  50. scanf("%d",&n);
  51.  
  52. //int ext[n+1];
  53. mp.clear();
  54. memset(a,0,mx);
  55.  
  56. for(int i =1; i <= n; i++){
  57. scanf("%s",word);
  58. //s1 = word;
  59. mp[word] = i;
  60.  
  61. }
  62. int y ,sum = 0;
  63. for(int i = 1; i<= n; i++){
  64. scanf("%s", word);
  65. //s1 = word;
  66. update(y = mp[word]);
  67. //cout<<ext[i]<<" ";
  68. sum += (y - count(y));
  69.  
  70. }
  71.  
  72. //cout<<endl;
  73.  
  74.  
  75. cout<<sum<<endl;
  76.  
  77. }
  78.  
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0s 2940KB
stdin
2
6
in the force strong you are
you are strong in the force
6
or i will help you not
or i will not help you
stdout
11
2