思路:偶数减奇数的前缀和,如果出现重复的数字,则该相同的值两个位置满足?
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll n;cin>>n;
vector<ll>a(n+1);
ll sum=0,x=0;
set<ll>d;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
if(i&1) sum+=-a[i];
else sum+=a[i];
if(sum==0) x++;
d.insert(sum);
}
ll s=d.size();
if(s==n&&x==0) cout<<"NO"<<'\n';
else cout<<"YES"<<'\n';
}
int main()
{
ll t;cin>>t;
while(t--) solve();
return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while(t--) {
int n; cin >> n;
vector<pair<int,int>> p(n);
vector<int> v(n);
for(int i = 0; i < n; i++) {
int x, y; cin >> x >> y;
p[i] = {x,y};
v[i] = y;
}
sort(p.begin(), p.end());
sort(v.begin(), v.end());
ll ans = 0;
for (int i = 0; i < n; i++) {
int x = p[i].second;
int k = lower_bound(v.begin(), v.end(), x) - v.begin();
ans += k;
v.erase(v.begin() + k, v.begin() + k + 1);
}
cout << ans << '\n';
}
return 0;
}