D
//考察代数变形,就是ai-i=aj-j
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
map<int, int> freq;
long long cnt = 0;
for (int i = 0; i < n; ++i) {
int b = a[i] - (i + 1);
cnt += freq[b];
freq[b]++;
}
cout << cnt << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
D
//很多这种操作后判断题,会引起一些性质的变化,要善于抓住
//对1234经行模拟后发现逆序数对成奇偶数分布
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int temp[100001];
int ans;
ll meger(int q[],int l,int r){
if(l>=r) return 0;
int mid = (l+r)>>1,k=0;
int i = l,j = mid+1;
ans = meger(q,l,mid)+meger(q,mid+1,r);
while(i<=mid&&j<=r){
if(q[i]<=q[j]) temp[k++] = q[i++];
else {
ans += mid -i+1;
temp[k++] = q[j++];
}
}
while(i<=mid) temp[k++] = q[i++];
while(j<=r) temp[k++] = q[j++];
for(int i = l,j=0;i<=r;j++,i++) q[i] = temp[j];
return ans;
}
void solve() {
int n;
cin>>n;
int a[n];
int b[n];
map<int,int> ma;
bool d=false;
ans=0;
for(int i=0;i<n;i++){ cin>>a[i];ma[a[i]]++;temp[i]=0;}
int ans1=meger(a,0,n-1);
ans=0;
for(int i=0;i<n;i++) {cin>>b[i];ma[b[i]]--;if(ma[b[i]]<0)d=true;temp[i]=0;}
int ans2=meger(b,0,n-1);
if(d) {cout<<"NO\n";return ;}
if((ans1&1)==(ans2&1)){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
int main() {
int t;
cin>>t;
while(t--){
solve();
}
}
A
//直接贪心模拟吧
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n, m;
cin >> n >> m;
vector<ll> b(n);
vector<ll> g(m);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < m; i++) {
cin >> g[i];
}
sort(b.begin(), b.end());
sort(g.begin(), g.end());
if (b[n-1] > g[0]) {
cout << -1 << endl;
return;
}
ll sum=0;
if(b[n-1] < g[0]){
for(int i=0;i<n-2;i++){
for(int j=0;j<m;j++){
sum+=b[i];
}
}
for(int i=0;i<m;i++){
sum+=g[i];
}
for(int i=0;i<m-1;i++){
sum+=b[n-2];
}
sum+=b[n-1];
}else{
//cout<<11;
for(int i=0;i<n-1;i++){
for(int j=0;j<m;j++){
sum+=b[i];
}
}
for(int i=0;i<m;i++){
sum+=g[i];
}
}
cout << sum << endl;
}
int main() {
solve();
return 0;
}