Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define nguyendz the_best
  3.  
  4. #define all(n) n.begin(),n.end()
  5. #define ll int
  6. #define ld long double
  7. #define pb push_back
  8. #define eb emplace_back
  9. #define endl "\n"
  10. #define pll pair<ll,ll>
  11. #define YES cout <<"YES"<<endl;
  12. #define NO cout <<"NO"<<endl;
  13. #define ff first
  14. #define ss second
  15. //#define ((x|y)-y) (x&(~y))
  16.  
  17. using namespace std;
  18. const ll maxn=1e4+2;
  19. const ll maxx=1e13;
  20. const ll mod=1e9+7;
  21. const ll mod1=998244353;
  22.  
  23.  
  24. ll kc,t,n;
  25. struct tk
  26. {
  27. ll id,val;
  28. };
  29. ll a[maxn];
  30.  
  31. int main()
  32. {
  33. // freopen("test.txt","r",stdin);
  34. // freopen("CHEMIST.OUT","w",stdout);
  35. ios_base::sync_with_stdio(false);
  36. cin.tie(0);
  37. cout.tie(0);
  38. ll n,l,r;
  39. cin>>n>>l>>r;
  40. for (int i=1;i<=n;i++)
  41. {
  42. ll k;
  43. cin>>k;
  44. a[i]=a[i-1]+k;
  45.  
  46. }
  47. sort(a+1,a+n+1);
  48. ll ans=0;
  49. for (int i=1;i<=n;i++)
  50. {
  51. ll t1=a[i-1]+l,t2=a[i-1]+r;
  52. ll d=1,h=n;
  53. while (d<=h)
  54. {
  55. ll m=(d+h)/2;
  56. if (a[m]<t1) d=m+1;
  57. else h=m-1;
  58. }
  59. ll v1,v2;
  60. v1=d;
  61. d=1,h=n;
  62. while (d<=h)
  63. {
  64. ll m=(d+h)/2;
  65. if (a[m]<t2) d=m+1;
  66. else h=m-1;
  67. }
  68. v2=d;
  69. // cout <<v1<<" "<<v2<<endl;
  70. ans=ans+v2-v1+1;
  71. }
  72. cout <<ans;
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement