The meaning of the question: There are n kinds of money in the wallet, and then there are m times of inquiries to ask how many numbers can be represented in the [l,r] interval.
Solution: This question was recommended by the group owner, and then asked me to write it with bitset. He said that the time required to operate 32 bitsets == the time required to operate one int, so some problems can be solved quickly by using bitsets .
The idea of this topic is to write a few scribbles, and then just ask for a prefix and sum.
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); 4 #define LL long long 5 #define ULL unsigned LL 6 #define fi first 7 #define se second 8 #define pb push_back 9 #define lson l,m,rt<<1 10 #define rson m+1,r,rt<<1|1 11 #define max3(a,b,c) max(a,max(b,c)) 12 #define min3(a,b,c) min(a,min(b,c)) 13 typedef pair<int,int> pll; 14 const int INF = 0x3f3f3f3f; 15 const LL mod = 1e9+7; 16 const int N = 1e5+10; 17 bitset<N> b; 18 int tot[N]; 19 int main(){ 20 //Fopen; 21 b[0] = 1; 22 int n, m; 23 scanf("%d%d", &n, &m); 24 int t; 25 for(int i = 1; i <= n; i++){ 26 scanf("%d", &t); 27 b |= (b << t); 28 } 29 tot[0] = 1; 30 for(int i = 1; i < N; i++) 31 tot[i] = tot[i-1] + b[i]; 32 int l, r; 33 while(m--){ 34 scanf("%d%d",&l,&r); 35 printf("%d\n",tot[r] - tot[l-1]); 36 } 37 return 0; 38 }