#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<0?-(x):x) #define pow2(x) ((x)*(x)) #define rep(i,n) for(int i=0; i=0; --i) #define repl(i,s,n) for(int i=s; i<=n; ++i) #define replr(i,s,n) for(int i=n; i>=s; --i) #define repf(i,s,n,j) for(int i=s; i<=n; i+=j) #define repe(e,obj) for(auto e : obj) #define SP << " " << #define COL << " : " << #define COM << ", " << #define ARR << " -> " << #define PNT(STR) cout << STR << endl #define POS(X,Y) "(" << X << ", " << Y << ")" #define DEB(A) " (" << #A << ") " << A #define DEBREP(i,n,val) for(int i=0; i P; typedef pair PI; typedef pair IP; typedef pair PP; typedef priority_queue, greater

> pvqueue; #define N 1007 #define LV 18 class MergeSortTree { vector data[N]; vector sum[N]; int n0, n; void build(int k, int l, int r, ll *a) { if(l+1 == r) { if(l < n) data[k].push_back(a[l]); sum[k].push_back(0); sum[k].push_back(a[l]); return; } int m = (l+r)/2; if(l < m) build(2*k+1, l, m, a); if(m < r) build(2*k+2, m, r, a); int sz = data[2*k+1].size() + data[2*k+2].size(); data[k].resize(sz); sum[k].resize(sz+1); merge(data[2*k+1].begin(), data[2*k+1].end(), data[2*k+2].begin(), data[2*k+2].end(), data[k].begin()); sum[k][0] = 0; for(int i=0; i> n >> q; rep(i, n) cin >> a[i]; MergeSortTree mst(n, a); while(q--) { int t, l, r, x; cin >> t >> l >> r >> x; cout << mst.query(l-1, r, x) << endl; } return 0; }