fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pii pair<ll,ll>
  5. const ll N=1000005;
  6. const ll inf=1e18;
  7. ll pow10[20];
  8. ll change_len(ll x)
  9. {
  10. ll cnt=0;
  11. while(x)
  12. {
  13. x/=10;
  14. cnt++;
  15. }
  16. return cnt;
  17. }
  18. void solve()
  19. {
  20. ll n,l,r;
  21. cin>>n>>l>>r;
  22. vector<ll>a(n+5);
  23. for(ll i=1;i<=n;i++)
  24. {
  25. cin>>a[i];
  26. }
  27. sort(a.begin()+1,a.begin()+n+1);
  28. ll ans=0;
  29. for(ll i=1;i<=n;i++)
  30. {
  31. ll len=change_len(a[i]);
  32. ll left=(l-a[i]+pow10[len]-1)/pow10[len];
  33. ll right=(r-a[i])/pow10[len];
  34. if(left<=right)
  35. {
  36. ans+=upper_bound(a.begin()+1,a.begin()+n+1,right)-lower_bound(a.begin()+1,a.begin()+n+1,left);
  37. }
  38. }
  39. cout<<ans<<"\n";
  40. }
  41.  
  42. int main()
  43. {
  44. //freopen(".inp","r",stdin);
  45. //freopen(".out","w",stdout);
  46. ios_base::sync_with_stdio(0);
  47. cin.tie(0);cout.tie(0);
  48. ll T;
  49. cin>>T;
  50. pow10[0]=1;
  51. for(int i=1;i<=16;i++) pow10[i]=pow10[i-1]*10;
  52. while(T--)
  53. {
  54. solve();
  55. }
  56. return 0;
  57. }
  58. /*
  59.  
  60.   l<= x*10^lenai + a[i]<=r
  61.   (l-a[i])/p <= x <= (r-a[i])/p
  62.  
  63. */
Runtime error #stdin #stdout #stderr 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc