fork download
  1. # include <iostream>
  2. # include <fstream>
  3. # include <sstream>
  4. # include <algorithm>
  5. # include <cstdio>
  6. # include <cmath>
  7. # include <numeric>
  8. # include <cstdlib>
  9. # include <cstring>
  10. # include <vector>
  11. # include <list>
  12. # include <set>
  13. # include <map>
  14. # include <stack>
  15. # include <queue>
  16. # include <cctype>
  17. # include <climits>
  18. # include <complex>
  19.  
  20. using namespace std;
  21.  
  22. typedef long long ll;
  23. typedef unsigned long long ull;
  24. typedef pair<int,int> pii;
  25. typedef vector<int> vi;
  26. #define rep(i,a,b) for(int i=a;i<b;i++)
  27. #define pb push_back
  28. #define mp make_pair
  29. #define inf 1000000000
  30. #define mod 1000000007
  31. #define mst(a,b) memset(a,b,sizeof(a))
  32. #define pi (double)(3.141592653589793)
  33.  
  34. long long p[100010],q[100010],r[100010],xx[100010],yy[100010];
  35.  
  36. int main()
  37. {
  38. long long t,i,j,k,a,b,c,x;
  39. cin>>t;
  40. long long sum=0;
  41. while(t--)
  42. {
  43. sum=0;
  44. scanf("%lld",&a);
  45. for(i=1;i<=a;i++)
  46. scanf("%lld",&p[i]);
  47. scanf("%lld",&b);
  48. for(i=1;i<=b;i++)
  49. scanf("%lld",&q[i]);
  50. scanf("%lld",&c);
  51. for(i=1;i<=c;i++)
  52. scanf("%lld",&r[i]);
  53.  
  54. for(i=1;i<=b;i++)
  55. {
  56. x=(lower_bound(r+i,r+c+1,q[i])-(r));
  57. xx[i]=c-x+1;
  58.  
  59.  
  60. }
  61. for(i=(b-1);i>=1;i--)
  62. {
  63. xx[i]+=xx[i+1];
  64.  
  65. }
  66. for(i=1;i<=a;i++)
  67. {
  68. x=(lower_bound(q+i,q+b+1,p[i])-(q));
  69. yy[i]=x;
  70.  
  71. }
  72. for(i=1;i<=a;i++)
  73. if(yy[i]<=b)
  74. sum+=(xx[yy[i]]);
  75. cout<<sum<<endl;
  76.  
  77. }
  78. return 0;
  79. }
Success #stdin #stdout 0s 6636KB
stdin
1
3
1 5 6
3
2 3 4
3
7 8 9
stdout
6