fork download
  1. /*
  2. * @Author: hungeazy
  3. * @Date: 2026-04-05 14:07:57
  4. * @Last Modified by: hungeazy
  5. * @Last Modified time: 2026-04-05 14:29:40
  6. */
  7. #include <bits/stdc++.h>
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10. // #pragma GCC optimize("O3")
  11. // #pragma GCC optimize("unroll-loops")
  12. // #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
  13. using namespace std;
  14. using namespace __gnu_pbds;
  15. bool M1;
  16. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  17. #define int long long
  18. #define ll long long
  19. #define ull unsigned long long
  20. #define sz(x) x.size()
  21. #define sqr(x) (1LL * (x) * (x))
  22. #define all(x) x.begin(), x.end()
  23. #define fill(f,x) memset(f,x,sizeof(f))
  24. #define FOR(i,l,r) for(int i=l;i<=r;i++)
  25. #define FOD(i,r,l) for(int i=r;i>=l;i--)
  26. #define debug(x) cout << #x << " = " << x << '\n'
  27. #define ii pair<int,int>
  28. #define iii pair<int,ii>
  29. #define di pair<ii,ii>
  30. #define vi vector<int>
  31. #define vii vector<ii>
  32. #define mii map<int,int>
  33. #define fi first
  34. #define se second
  35. #define pb push_back
  36. #define MOD 1000000007
  37. #define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
  38. #define YES cout << "YES\n"
  39. #define NO cout << "NO\n"
  40. #define MASK(i) (1LL << (i))
  41. #define c_bit(i) __builtin_popcountll(i)
  42. #define BIT(x,i) ((x) & MASK(i))
  43. #define SET_ON(x,i) ((x) | MASK(i))
  44. #define SET_OFF(x,i) ((x) & ~MASK(i))
  45. #define oo 1e18
  46. #define name ""
  47. #define endl '\n'
  48. #define memory() cerr << abs(&M2-&M1)/1024.0/1024 << " MB" << endl
  49. #define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms." << endl
  50. template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
  51. template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
  52. template <class T> using ordered_set = tree <T, null_type, less_equal <T>, rb_tree_tag,tree_order_statistics_node_update>;
  53. const int N = (int)2e5+10;
  54. int n,L,R,a[N<<1];
  55.  
  56. namespace sub2 {
  57.  
  58. int res[N<<1],pre[N<<1];
  59.  
  60. bool approved() {
  61. return n <= 5e3;
  62. }
  63.  
  64. void solve(void)
  65. {
  66. FOR(i,1,n) a[i+n] = a[i];
  67. FOR(i,1,2*n) pre[i] = pre[i-1]+a[i];
  68. FOR(x,1,n)
  69. FOR(y,x,x+n-2)
  70. if (pre[y]-pre[x-1] >= L and pre[y]-pre[x-1] <= R)
  71. {
  72. res[x]++;
  73. res[y+1]--;
  74. }
  75. FOR(i,1,2*n) res[i] += res[i-1];
  76. FOR(i,1,n) cout << res[i]+res[i+n] << " ";
  77. }
  78.  
  79. }
  80.  
  81. namespace sub4 {
  82.  
  83. int pre[N<<1],numStart[N<<1],numEnd[N<<1],res[N];
  84.  
  85. struct FenwickTree {
  86. vi bit;
  87. int n;
  88.  
  89. FenwickTree() {};
  90. FenwickTree(int _n):
  91. n(_n), bit(_n+1,0) {};
  92.  
  93. void clear() {
  94. FOR(i,0,n) bit[i] = 0;
  95. }
  96.  
  97. void update(int id, int val)
  98. {
  99. while (id <= n)
  100. {
  101. bit[id] += val;
  102. id += (id&(-id));
  103. }
  104. }
  105.  
  106. int get(int id)
  107. {
  108. int ans = 0;
  109. while (id)
  110. {
  111. ans += bit[id];
  112. id -= (id&(-id));
  113. }
  114. return ans;
  115. }
  116.  
  117. int get(int l, int r) {
  118. return get(r)-get(l-1);
  119. }
  120. } BIT;
  121.  
  122. void solve(void)
  123. {
  124. FOR(i,1,n) a[i+n] = a[i];
  125. FOR(i,1,2*n) pre[i] = pre[i-1]+a[i];
  126. vi comp;
  127. FOR(i,0,2*n)
  128. {
  129. comp.pb(pre[i]);
  130. comp.pb(pre[i]-L);
  131. comp.pb(pre[i]-R);
  132. comp.pb(pre[i]+L);
  133. comp.pb(pre[i]+R);
  134. }
  135. sort(all(comp));
  136. comp.erase(unique(all(comp)),comp.end());
  137. int len = sz(comp);
  138. BIT = FenwickTree(len);
  139. FOR(i,2,n)
  140. {
  141. int pos = lower_bound(all(comp),pre[i])-comp.begin()+1;
  142. BIT.update(pos,1);
  143. }
  144. FOR(i,n+1,2*n)
  145. {
  146. int x = lower_bound(all(comp),pre[i]-L)-comp.begin()+1;
  147. int y = lower_bound(all(comp),pre[i]-R)-comp.begin()+1;
  148. numEnd[i-n] = BIT.get(y,x);
  149. int pos = lower_bound(all(comp),pre[i-n+1])-comp.begin()+1;
  150. BIT.update(pos,-1);
  151. pos = lower_bound(all(comp),pre[i])-comp.begin()+1;
  152. BIT.update(pos,1);
  153. }
  154. BIT.clear();
  155. FOR(i,1,n-2)
  156. {
  157. int pos = lower_bound(all(comp),pre[i])-comp.begin()+1;
  158. BIT.update(pos,1);
  159. }
  160. FOR(i,1,n)
  161. {
  162. int pos = lower_bound(all(comp),pre[i+n-2])-comp.begin()+1;
  163. BIT.update(pos,1);
  164. int x = lower_bound(all(comp),pre[i-1]+L)-comp.begin()+1;
  165. int y = lower_bound(all(comp),pre[i-1]+R)-comp.begin()+1;
  166. numStart[i] = BIT.get(x,y);
  167. pos = lower_bound(all(comp),pre[i])-comp.begin()+1;
  168. BIT.update(pos,-1);
  169. }
  170. BIT.clear();
  171. int l = n, r = 2*n-1;
  172. FOR(i,n+1,2*n-1)
  173. {
  174. int pos = lower_bound(all(comp),pre[i])-comp.begin()+1;
  175. BIT.update(pos,1);
  176. }
  177. FOD(i,n,2)
  178. {
  179. int x = lower_bound(all(comp),pre[i]+L)-comp.begin()+1;
  180. int y = lower_bound(all(comp),pre[i]+R)-comp.begin()+1;
  181. res[1] += BIT.get(x,y);
  182. int pos = lower_bound(all(comp),pre[i+n-1])-comp.begin()+1;
  183. BIT.update(pos,-1);
  184. }
  185. FOR(i,2,n) res[i] += res[i-1]+numStart[i]-numEnd[i-1];
  186. FOR(i,1,n) cout << res[i] << " ";
  187. }
  188.  
  189. }
  190.  
  191. bool M2;
  192. signed main()
  193. {
  194. fast;
  195. if (fopen(name".inp","r"))
  196. {
  197. freopen(name".inp","r",stdin);
  198. freopen(name".out","w",stdout);
  199. }
  200. cin >> n >> L >> R;
  201. FOR(i,1,n) cin >> a[i];
  202. // if (sub2::approved()) return sub2::solve(), time(), memory(), 0;
  203. sub4::solve();
  204. time();
  205. memory();
  206. return 0;
  207. }
  208. // ██░ ██ █ ██ ███▄ █ ▄████
  209. //▓██░ ██▒ ██ ▓██▒ ██ ▀█ █ ██▒ ▀█▒
  210. //▒██▀▀██░▓██ ▒██░▓██ ▀█ ██▒▒██░▄▄▄░
  211. //░▓█ ░██ ▓▓█ ░██░▓██▒ ▐▌██▒░▓█ ██▓
  212. //░▓█▒░██▓▒▒█████▓ ▒██░ ▓██░░▒▓███▀▒
  213. // ▒ ░░▒░▒░▒▓▒ ▒ ▒ ░ ▒░ ▒ ▒ ░▒ ▒
  214. // ▒ ░▒░ ░░░▒░ ░ ░ ░ ░░ ░ ▒░ ░ ░
  215. // ░ ░░ ░ ░░░ ░ ░ ░ ░ ░ ░ ░ ░
  216. // ░ ░ ░ ░ ░ ░
Success #stdin #stdout #stderr 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
-------------Time:4.816ms.
19.8375 MB