题目链接:https://www.luogu.com.cn/problem/P8667
二分
用lower_bound和upper_bound
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
const ll N = 1e5;
ll op1[N],op2[N],op3[N];
void solve(){
ll n;
std::cin >> n;
for(ll i = 1; i <= n; i ++){
std::cin >> op1[i];
}
for(ll i = 1; i <= n; i ++){
std::cin >> op2[i];
}
for(ll i = 1; i <= n; i ++){
std::cin >> op3[i];
}
std::sort(op1 + 1,op1 + n + 1);
std::sort(op2 + 1,op2 + n + 1);
std::sort(op3 + 1,op3 + n + 1);
ll res = 0;
for(ll i = 1; i <= n; i ++){
ll re = std::lower_bound(op1 + 1,op1 + n + 1,op2[i]) - op1 - 1;
// std::cout << re << " ";
// ll *jj = std::upper_bound(op2 + 1,op2 + n + 1,op1[i]);
ll rk = std::upper_bound(op3 + 1,op3 + n + 1,op2[i]) - op3;
rk = n - rk + 1;
// std::cout << rk << "\n";
res += (re * rk);
}
std::cout << res << "\n";
}
int main(){
ll t = 1;
while(t --)
solve();
return 0;
}
26秒前,还热乎