一、题目描述
二、问题简析
题目要求:
\[\begin{split} &1 \leq i,j,k \leq N \\ &A_i < B_j < C_k \end{split} \]改变一下,得到
\[\begin{cases} A_i < B_j \\ C_k > B_j \end{cases} \]对于一个确定的 \(B_j\),统计所有 \(< B_j\) 的 \(A_i\) 的数量 cntA
,统计所有 \(> B_j\) 的 \(C_k\) 的数量 cntC
,对于该 \(B_j\) 解的数量为 cntA * cntC
。
AC代码
复杂度:\(O(NlogN)\)$
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int quickin(void)
{
int ret = 0;
bool flag = false;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-') flag = true;
ch = getchar();
}
while (ch >= '0' && ch <= '9' && ch != EOF)
{
ret = ret * 10 + ch - '0';
ch = getchar();
}
if (flag) ret = -ret;
return ret;
}
const int MAX = 1e5 + 3;
int A[MAX], B[MAX], C[MAX], n;
int main()
{
#ifdef LOCAL
freopen("test.in", "r", stdin);
#endif
n = quickin();
for (int i = 1; i <= n; i++)
A[i] = quickin();
for (int i = 1; i <= n; i++)
B[i] = quickin();
for (int i = 1; i <= n; i++)
C[i] = quickin();
sort(A + 1, A + 1 + n);
sort(C + 1, C + 1 + n);
ll ans = 0;
for (int i = 1; i <= n; i++)
{
int cntA = lower_bound(A + 1, A + 1 + n, B[i]) - A - 1;
int cntC = C + n - upper_bound(C + 1, C + 1 + n, B[i]) + 1;
ans += (ll)cntA * cntC;
}
cout << ans << endl;
return 0;
}
完
标签:ch,int,递增,long,三元组,getchar From: https://www.cnblogs.com/hoyd/p/18058353