Naxocist

codecube_227

Mar 23rd, 2024
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void dbg_out() { cerr << endl; }
  5. template<typename Head, typename... Tail>
  6. void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
  7. #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
  8.  
  9. template<typename S, typename T> S amax(S &a, const T &b) { if(b > a) a = b; return a; }
  10. template<typename S, typename T> S amin(S &a, const T &b) { if(b < a) a = b; return a; }
  11.  
  12. #define all(x) x.begin(), x.end()
  13. #define allrev(x) x.rbegin(), x.rend()
  14. #define pb emplace_back
  15. #define sz(x) (int) (x).size()
  16. #define ln '\n'
  17. using ll = long long;
  18. using pi = pair<ll, ll>;
  19. using T = tuple<ll, ll, ll>;
  20. const ll INF = 2e9;
  21. const ll N = 1e5 + 3, K = 103, mod = 1e9 + 7;
  22. ll dp[N][K], res[K];
  23.  
  24. void add(ll &x, ll y) { x += y, x %= mod; }
  25. void sub(ll &x, ll y) { x -= y, x %= mod, x += mod, x %= mod; }
  26.  
  27. void runcase() {
  28.     int n, q; cin >> n >> q;
  29.  
  30.     dp[0][0] = 1;
  31.     for(int i=1; i<=n; ++i) {
  32.         int x; cin >> x;
  33.         for(int j=0; j<K; ++j) {
  34.             add(dp[i][j], dp[i-1][j]);
  35.             if(j >= x) add(dp[i][j], dp[i-1][j-x]);
  36.         }
  37.     }
  38.  
  39.     while(q--) {
  40.         int l, r, k; cin >> l >> r >> k;
  41.         for(int i=0; i<=k; ++i) {
  42.             res[i] = dp[r][i];
  43.             for(int j=0; j<i; ++j) sub(res[i], res[j]*dp[l-1][i-j]);
  44.         }
  45.         cout << res[k] << ln;
  46.     }
  47.     return ;
  48. }
  49.  
  50. int32_t main() {
  51.     cin.tie(nullptr)->sync_with_stdio(0);
  52.     int TC = 1;
  53.     // cin >> TC;
  54.     while(TC--) runcase();
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment