Educational Codeforces Round 94 (Rated for Div. 2) D. Zigzags 题解
题意
给你一个数组
2
5
2 2 2 2 2
6
1 3 3 1 2 3
5
2
思路
问题可以转化为:当
具体实现:枚举
具体表现为:
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define flase false
#define ture true
#define ft first
#define sd second
#define int long long
#define startt cout<<"----------start----------\n";
#define endd cout<<"-----------end-----------\n";
#define No cout<<"No\n"
#define Yes cout<<"Yes\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 200010;
const int M = N * 2;
const int mod = 1e9 + 7;
const double Pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
template <typename T>
T read() {
T sum = 0, fl = 1;
int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') fl = -1;
for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
return sum * fl;
}
template <typename T>
void print(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
vector<int> a;
int n, m, k;
//Let's BEGIN!!!==============================================================
void solve() {
cin >> n;
a = vector<int> (n);
for (auto &x : a) {
cin >> x;
}
vector<int> cnt(n * (n + 1) + 1, 0);
int tot = 0;
for (int j = n - 1; j >= 0; --j) {
int k = j + 1;
for (int l = k + 1; l < n; ++ l) {
cnt[a[k] * n + a[l]] += 1;
}
for (int i = 0; i < j; ++ i) {
tot += cnt[a[i] * n + a[j]];
}
}
cout << tot << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)