fork download
  1. #include<bits/stdc++.h>
  2. #define REP(i,n) for(int (i)=0;i<(int)(n);++(i))
  3. #define REPIT(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
  4. #define PB push_back
  5. #define FT first
  6. #define SD second
  7. #define ZERO(x) memset(x,0,sizeof(x))
  8. #define NEG(x) memset(x,-1,sizeof(x))
  9. #define RI(x) scanf("%d",&(x))
  10. #define RII(x,y) scanf("%d%d",&(x),&(y))
  11. #define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
  12. #define OIII(x,y,z) printf("%d %d %d\n",(x),(y),(z))
  13. #define OII(x,y) printf("%d %d\n",(x),(y))
  14. #define OI(x) printf("%d\n",(x))
  15. #define OL(x) cout<<(x)<<endl
  16. #define OLL(x,y) cout<<(x)<<" "<<(y)<<endl
  17. #define OLLL(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
  18. #define RS(s) scanf("%s",(s))
  19. #define MP(x,y) make_pair((x),(y))
  20. #define SZ(x) ((int)(x).size())
  21. #define FIN(f) freopen(f,"r",stdin)
  22. #define FOUT(f) freopen(f,"w",stdout)
  23. typedef long long LL;
  24. using namespace std;
  25. typedef pair<int,int> PII;
  26. const int MOD = 1e9+7;
  27. const int maxn = 111;
  28. int n;
  29. int a[11111];
  30. int main(int argc, char const *argv[])
  31. {
  32. int t;
  33. RI(t);
  34. while(t--) {
  35. RI(n);
  36. REP(i,n)RI(a[i]);
  37. sort(a,a+n);
  38. int ans = 0;
  39. int j=0;
  40. for(int i=1;i<n;++i) {
  41. while(a[j] <= a[i]-32)j++;
  42. ans += i-j;
  43. }
  44. OI(ans);
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 3184KB
stdin
2
4
1 16 32 64
5
1 100 110 100 1
stdout
3
4