fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int fun(vector<int> &x, vector<int> &y)
  5. {
  6. int cnt = 0;
  7. int n = x.size();
  8.  
  9. for(int i = 0; i < n; i++)
  10. {
  11. bool flag = true;
  12.  
  13. for(int j = 0; j < n; j++)
  14. {
  15. if(x[(i + j) % n] >= y[j])
  16. flag = false;
  17. }
  18.  
  19. if(flag == true)
  20. cnt ++;
  21. }
  22. return cnt;
  23. }
  24.  
  25. void solve()
  26. {
  27. int n;
  28. cin >> n;
  29.  
  30. vector<int> a(n), b(n), c(n);
  31.  
  32. for(int i = 0; i < n; i++)
  33. cin >> a[i];
  34. for(int i = 0; i < n; i++)
  35. cin >> b[i];
  36. for(int i = 0; i < n; i++)
  37. cin >> c[i];
  38.  
  39. cout << 1LL * n * fun(a, b) * fun(b, c) << endl;
  40. }
  41.  
  42. int main() {
  43. // your code goes here
  44. int t;
  45. cin >> t;
  46.  
  47. while(t--)
  48. solve();
  49. }
Success #stdin #stdout 0s 5324KB
stdin
4
2
1 2
3 4
5 4
3
1 1 1
2 2 2
3 3 3
4
1 2 1 2
3 3 2 2
5 5 5 5
5
1 4 2 3 5
6 4 5 7 6
7 5 8 10 10
stdout
4
27
0
10