#ifndef akinyan #define akinyan #include using namespace std; using ch = char; using ll = long long; using ld = long double; using db = double; using st = string; using vdb = vector; using vvdb = vector; using vl = vector; using vvl = vector; using vvvl = vector; using vd = vector; using vvd = vector; using vs = vector; using vvs = vector; using vc = vector; using vvc = vector; using vb = vector; using vvb = vector; using vvvb = vector; const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1000000000000000000LL; using pall = pair; using vp = vector; #endif #include ll op(ll a, ll b){ return a + b; } ll e(){ return 0; } int main(){ ll N,Q; cin>>N>>Q; vp A(N); set X; for(int i=0; i> A[i].first; A[i].second = i; } vl P(N); sort(A.begin(),A.end()); P[A[0].second] = 0; for(int i=1; i Seg(N); for(int i=0; i>x>>y; x--,y--; if(P[x] <= P[y]){ cout << 0 << endl; } else{ cout << Seg.prod(P[y] + 1,P[x]) << endl; } } }