Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned int uint;
typedef unsigned long long ulint;
constexpr lint mod1 = 1e9+7;

template<typename T>
struct ST{
  using F = function<T(T, T)>;
  int size_ = 1; vector<T> node; T initial; F query_, update_;
  ST(int n, T initial, F query, F update){
    while(size_ < n) size_ *= 2;
    node.resize(2*size_-1, initial);
    query_ = query;
    update_ = update;
  }
  void printnodes(){
    rep(i, node.size()) cout << node[i] << endl;
    return;
  }
  void build(vector<T> v){
    rep(i, v.size()) node[i+size_-1] = v[i];
    rrep(i, size_ - 1) node[i] = query_(node[2*i+1], node[2*i+2]);
    return;
  }
  void update(int j, T x){
    j += size_-1;
    node[j] = update_(node[j], x);
    while(j > 0){
      j = (j-1)/2;
      node[j] = query_(node[2*j+1], node[2*j+2]);
    }
    return;
  }
  T query(int l, int r){
    l += size_-1;
    r += size_-1;
    T ql = node[l], qr = node[r];
    while(l < r-1){
      if(l % 2 == 1) ql = query_(node[l], node[l+1]);
      if(r % 2 == 0) qr = query_(node[r-1], node[r]);
      l = (l-1)/2;
      r = (r-1)/2;
    }
    return query_(ql, qr);
  }
  int lb(T x){
    int tmp = 0;
    while(tmp < n-1){
      if(x <= node[tmp*2+1]) tmp = tmp*2+1;
      else tmp = tmp*2+2;
    }
    return tmp-size_+2;
  }
  int ub(T x){
    int tmp = 0;
    while(tmp < n-1){
      if(x < node[tmp*2+1]) tmp = tmp*2+1;
      else tmp = tmp*2+2;
    }
    return tmp-size_+2;
  }
};

int main() {
  lint n, s = 0;
  cin >> n;
  vector<lint> a(n), b(n), c(n);
  rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) cin >> c[i];
  sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());
  auto f = [](lint p, q){return max(p, q);};
  auto g = [](lint p, q){return q;};
  ST<lint> sta(n, 0, f, g), stc(n, 0, f, g);
  sta.build(a); stc.build(c);
  rep(i, n) s += sta.lb(b[i]) * (n - stc.ub(b[i]));
  cout << s << endl;
  return 0;
}

Compiler output:
a.cc: In member function 'int ST<T>::lb(T)':
a.cc:54:17: error: 'n' was not declared in this scope
   54 |     while(tmp < n-1){
      |                 ^
a.cc: In member function 'int ST<T>::ub(T)':
a.cc:62:17: error: 'n' was not declared in this scope
   62 |     while(tmp < n-1){
      |                 ^
a.cc: In function 'int main()':
a.cc:76:23: error: 'q' has not been declared
   76 |   auto f = [](lint p, q){return max(p, q);};
      |                       ^
a.cc: In lambda function:
a.cc:76:40: error: 'q' was not declared in this scope
   76 |   auto f = [](lint p, q){return max(p, q);};
      |                                        ^
a.cc: In function 'int main()':
a.cc:77:23: error: 'q' has not been declared
   77 |   auto g = [](lint p, q){return q;};
      |                       ^
a.cc: In lambda function:
a.cc:77:33: error: 'q' was not declared in this scope
   77 |   auto g = [](lint p, q){return q;};
      |                                 ^
a.cc: In function 'int main()':
a.cc:78:26: error: no matching function for call to 'ST<long long int>::ST(lint&, int, main()::<lambda(lint, int)>&, main()::<lambda(lint, int)>&)'
   78 |   ST<lint> sta(n, 0, f, g), stc(n, 0, f, g);
      |                          ^
a.cc:16:3: note: candidate: 'ST<T>::ST(int, T, F, F) [with T = long long int; F = std::function<long long int(long long int, long long int)>]'
   16 |   ST(int n, T initial, F query, F update){
      |   ^~
a.cc:16:26: note:   no known conversion for argument 3 from 'main()::<lambda(lint, int)>' to 'ST<long long int>::F' {aka 'std::function<long long int(long long int, long long int)>'}
   16 |   ST(int n, T initial, F query, F update){
      |                        ~~^~~~~
a.cc:13:8: note: candidate: 'ST<long long int>::ST(const ST<long long int>&)'
   13 | struct ST{
      |        ^~
a.cc:13:8: note:   candidate expects 1 argument, 4 provided
a.cc:13:8: note: candidate: 'ST<long long int>::ST(ST<long long int>&&)'
a.cc:13:8: note:   candidate expects 1 argument, 4 provided
a.cc:78:43: error: no matching function for call to 'ST<long long int>::ST(lint&, int, main()::<lambda(lint, int)>&, main()::<lambda(lint, int)>&)'
   78 |   ST<lint> sta(n, 0, f, g), stc(n, 0, f, g);
      |                                           ^
a.cc:16:3: note: candidate: 'ST<T>::ST(int, T, F, F) [with T = long long int; F = std::function<long long int(long long int, long long int)>]'
   16 |   ST(int n, T initial, F query, F update){
      |   ^~
a.cc:16:26: note:   no known conversion for argument 3 from 'main()::<lambda(lint, int)>' to 'ST<long long int>::F' {aka 'std::function<long long int(long long int, long long int)>'}
   16 |   ST(int n, T initial, F query, F update){
      |                        ~~^~~~~
a.cc:13:8: note: candidate: 'ST<long long int>::ST(const ST<long long int>&)'
   13 | struct ST{
      |        ^~
a.cc:13:8: note:   candidate expects 1 argument, 4 provided
a.cc:13:8: note: candidate: 'ST<long long int>::ST(ST<long long int>&&)'
a.cc:13:8: note:   candidate expects 1 argument, 4 provided