CF round 789 C - Tokitsukaze and Strange Inequality
Tokitsukaze and Strange Inequality
维护二维前缀和 为前 i 个数中比 j 小的有几个
枚举 b,c,分别判断 a,d 有多少种,每对 b,c 的贡献为
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 5e3 + 10;
int n;
int s[N][N];//s[i][j]为前i个数中小于j的有几个
int p[N];
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
cin >> T;
while(T--)
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> p[i];
for (int j = 1; j <= n; j++)
s[i][j] = s[i-1][j];
for (int j = p[i]; j <= n; j++)
s[i][j]++;
}
ll ans = 0;
for (int b = 2; b <= n - 2; b++)
{
for (int c = b + 1; c <= n - 1; c++)
{
ll t1 = s[b-1][p[c] - 1];
ll t2 = s[n][p[b]] - s[c][p[b]];
ans += t1 * t2;
}
}
cout << ans << endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧