fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAXS = 100000;
  5.  
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9.  
  10. int N, Q;
  11. cin >> N >> Q;
  12.  
  13. bitset<MAXS + 1> bs;
  14. bs[0] = 1;
  15.  
  16. for (int i = 0; i < N; i++) {
  17. int x;
  18. cin >> x;
  19. bs |= (bs << x);
  20. }
  21.  
  22. vector<int> pref(MAXS + 1, 0);
  23. for (int i = 1; i <= MAXS; i++) {
  24. pref[i] = pref[i - 1] + bs[i];
  25. }
  26.  
  27. while (Q--) {
  28. int L, R;
  29. cin >> L >> R;
  30. cout << pref[R] - pref[L - 1] << '\n';
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty