#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); const int B = 316; int n, q; cin >> n >> q; int sz = (n + B - 1) / B; vector a(n); REP(i, n) cin >> a[i]; vector > > block(sz); REP(i, n) block[i / B].emplace_back(a[i], 0); vector > rui(sz); REP(i, sz) { int szsz = block[i].size(), mx = 0; REP(j, szsz) { if (block[i][j].first >= mx) { block[i][j].second = 1; mx = block[i][j].second; } } sort(ALL(block[i])); REP(j, szsz) rui[i].emplace_back((j == 0 ? 0 : rui[i].back()) + block[i][j].second); } while (q--) { int query, l, r; long long x; cin >> query >> l >> r; --l; --r; int l_b = l / B, r_b = r / B, ans = 0, mx = 0; if (l_b == r_b) { FOR(i, l, r + 1) { if (a[i] >= mx) { ++ans; mx = a[i]; } } } else { FOR(i, l, B * (l_b + 1)) { if (a[i] >= mx) { ++ans; mx = a[i]; } } FOR(i, l_b + 1, r_b) { int sz = block[i].size(); int idx = lower_bound(ALL(block[i]), make_pair(mx, 0)) - block[i].begin(); --idx; ans += rui[i][sz - 1] - (idx >= 0 ? rui[i][idx] : 0); mx = max(mx, block[i].back().first); } FOR(i, B * r_b, r + 1) { if (a[i] >= mx) { ++ans; mx = a[i]; } } } cout << ans << '\n'; } return 0; }