inlineintread(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
intmain(){ int t = read(); while (t--) { int n = read(); string s; cin >> s; int cnt = 0; vector<int> r; for (int i = 0; i < n; i++) r.emplace_back(s[i] - 'a'); sort(r.begin(), r.end()); r.erase(unique(r.begin(), r.end()), r.end());
vector<int> mp(30); for (int i = 0; i < r.size(); i++) mp[r[i]] = r[r.size() - 1 - i];
for (int i = 0; i < n; i++) s[i] = 'a' + mp[s[i] - 'a'];
#include<bits/stdc++.h> #define int long long usingnamespace std;
constint N = 2e5 + 10; int a[N];
inlineintread(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
signedmain(){ int t = read(); while (t--) { map<int, map<int, map<int, int>>> mp; map<int, map<int, int>>cul1, cul2, cul3; int n = read(); int ans = 0; for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n - 2; i++) { ans -= 3 * mp[a[i]][a[i + 1]][a[i + 2]]++;
ans += cul1[a[i]][a[i + 1]]++; ans += cul2[a[i]][a[i + 2]]++; ans += cul3[a[i + 1]][a[i + 2]]++; }
cout << ans << '\n'; } return0; }
D. Ingenuity-2
一个庞大的分类讨论题。考虑相对运动,即将 R 的运动看作 H 朝反方向的运动,只需 H 最后运动到原点即可(各方向运动代数和为0)