按绝对值排序后,用 01 数组表示奇偶性,
相邻的几个0(或1) 只能算作一个(题意)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int maxn = 1000000 + 7, INF = 0x3f3f3f3f, mod = 1e9+7;
int T, n, m, l, r;
int a[maxn];
struct node {
double v;
int f; // + = 1
}b[maxn];
bool cmp(node a, node b) {
return a.v < b.v;
}
void init() {
double x;
for(int i = 0; i < n; ++i) {
scanf("%lf", &x);
if(x > 0) {
b[i].v = x;
b[i].f = 1;
}
else {
b[i].v = -x;
b[i].f = 0;
}
}
sort(b, b+n, cmp);
}
void solve() {
for(int i = 0; i < n; ++i)
a[i] = b[i].f; //, cout << " ++ " << b[i].v << endl;;
int ans = 1;
for(int i = 1; i < n; ++i)
if(a[i] != a[i-1]) ans++;
cout << ans << endl;
}
int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
init();
solve();
}
return 0;
}